file-deletion-rules

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

File Deletion Rules

文件删除规则

Rule (CRITICAL)

规则(CRITICAL)

Skip if already deleted: If the target file does not exist in the working tree, do nothing. This rule applies only to files that currently exist.
NEVER use
rm
or
unlink
commands directly.
ALWAYS use git stash before deleting files to preserve them.
Apply without confirmation: When file deletion is needed, follow this rule without asking the user for confirmation. Execute the deletion process defined below.
若文件已删除则跳过:如果目标文件在工作区中不存在,则无需操作。本规则仅适用于当前存在的文件。
绝对禁止直接使用
rm
unlink
命令。
必须始终在删除文件前使用git stash以保留文件内容。
无需确认直接执行:当需要删除文件时,直接遵循本规则执行,无需向用户确认。执行以下定义的删除流程。

Prohibited Commands

禁止使用的命令

The following commands are strictly prohibited:
  • rm
    (any variant:
    rm -rf
    ,
    rm -f
    , etc.)
  • unlink
  • Any direct file deletion without git stash
以下命令严格禁止使用:
  • rm
    (任何变体:
    rm -rf
    rm -f
    等)
  • unlink
  • 任何未先执行git stash的直接文件删除操作

Deletion Process

删除流程

For Modified Files (Tracked & Modified)

针对已修改文件(已跟踪且已修改)

  1. Save changes to git stash:
    bash
    git stash push -m "[Deletion] <reason>" -- <files>
  2. Remove file from git:
    bash
    git rm <files>
  1. 将更改保存到git stash:
    bash
    git stash push -m "[Deletion] <reason>" -- <files>
  2. 从git中移除文件:
    bash
    git rm <files>

For New Files (Untracked)

针对新文件(未跟踪)

  1. Stage the file:
    bash
    git add <files>
  2. Save to stash (file is automatically removed from working tree):
    bash
    git stash push -m "[Deletion] <reason>" -- <files>
  1. 暂存文件:
    bash
    git add <files>
  2. 保存到stash(文件会自动从工作区移除):
    bash
    git stash push -m "[Deletion] <reason>" -- <files>

Stash Message Template

Stash消息模板

Use this format for stash messages:
text
[Deletion] <reason>
Files: <file1>, <file2>, ...
使用以下格式编写stash消息:
text
[Deletion] <reason>
Files: <file1>, <file2>, ...

Examples

示例

bash
undefined
bash
undefined

Single file

单个文件

git stash push -m "[Deletion] Remove deprecated API endpoints Files: api/old-endpoint.js" -- api/old-endpoint.js
git stash push -m "[Deletion] Remove deprecated API endpoints Files: api/old-endpoint.js" -- api/old-endpoint.js

Multiple files

多个文件

git stash push -m "[Deletion] Clean up unused test fixtures Files: test/fixtures/old.js, test/fixtures/deprecated.js" -- test/fixtures/old.js test/fixtures/deprecated.js
git stash push -m "[Deletion] Clean up unused test fixtures Files: test/fixtures/old.js, test/fixtures/deprecated.js" -- test/fixtures/old.js test/fixtures/deprecated.js

Directory

目录

git stash push -m "[Deletion] Remove legacy components Files: src/components/legacy/" -- src/components/legacy/
undefined
git stash push -m "[Deletion] Remove legacy components Files: src/components/legacy/" -- src/components/legacy/
undefined

Complete Examples

完整示例

Good: Deleting Modified File

正确操作:删除已修改文件

bash
undefined
bash
undefined

Step 1: Save to stash

步骤1:保存到stash

git stash push -m "[Deletion] Remove unused utility function Files: utils/old-helper.js" -- utils/old-helper.js
git stash push -m "[Deletion] Remove unused utility function Files: utils/old-helper.js" -- utils/old-helper.js

Step 2: Remove from git

步骤2:从git中移除

git rm utils/old-helper.js
undefined
git rm utils/old-helper.js
undefined

Good: Deleting Untracked File

正确操作:删除未跟踪文件

bash
undefined
bash
undefined

Step 1: Stage file

步骤1:暂存文件

git add temp-file.js
git add temp-file.js

Step 2: Save to stash (removes from working tree)

步骤2:保存到stash(从工作区移除)

git stash push -m "[Deletion] Remove temporary file Files: temp-file.js" -- temp-file.js
undefined
git stash push -m "[Deletion] Remove temporary file Files: temp-file.js" -- temp-file.js
undefined

Good: Deleting Multiple Files

正确操作:删除多个文件

bash
undefined
bash
undefined

Save all files to stash

将所有文件保存到stash

git stash push -m "[Deletion] Clean up deprecated modules Files: module1.js, module2.js, module3.js" -- module1.js module2.js module3.js
git stash push -m "[Deletion] Clean up deprecated modules Files: module1.js, module2.js, module3.js" -- module1.js module2.js module3.js

Remove from git

从git中移除

git rm module1.js module2.js module3.js
undefined
git rm module1.js module2.js module3.js
undefined

Bad: Direct Deletion

错误操作:直接删除

bash
undefined
bash
undefined

DO NOT USE

禁止使用

rm file.js rm -rf directory/ unlink file.js
undefined
rm file.js rm -rf directory/ unlink file.js
undefined

Notes

注意事项

  • Files saved to git stash can be recovered later if needed
  • Use descriptive reasons in stash messages for future reference
  • The stash preserves file contents even after deletion
  • List all files in the stash message for clarity
  • 保存到git stash的文件可在后续需要时恢复
  • 在stash消息中使用描述性的原因,方便日后查阅
  • Stash会在删除后保留文件内容
  • 在stash消息中列出所有文件以确保清晰

Related Skills

相关技能

  • git-operations-rules - General git operation rules (unstage, undo, stash)
  • git-operations-rules - Git通用操作规则(取消暂存、撤销、stash)