git-safety
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Safety & Standards
Git Safety & Standards
该 Skill 旨在确保在 Git 仓库中进行文件操作时的安全性和历史完整性。
This Skill is designed to ensure security and historical integrity when performing file operations in a Git repository.
核心准则
Core Guidelines
1. 移动与重命名 (Move & Rename)
1. Move & Rename
- 禁止直接使用 命令操作受 Git 跟踪的文件。
mv - 强制使用 。
git mv <old_path> <new_path> - 理由:确保 Git 自动跟踪文件重构,保留文件的 Git History,避免识别为“删除 + 新增”。
- Prohibited: Direct use of the command to manipulate Git-tracked files.
mv - Mandatory: Use .
git mv <old_path> <new_path> - Rationale: Ensures Git automatically tracks file restructuring, preserves Git History, and avoids being identified as "delete + add".
2. 删除 (Delete)
2. Delete
- 禁止直接使用 或
rm操作受 Git 跟踪的文件。rm -rf - 强制使用 或
git rm <path>。git rm -r <path> - 理由:直接从工作区和索引中同步移除,避免残留未跟踪的删除变更。
- Prohibited: Direct use of or
rmto manipulate Git-tracked files.rm -rf - Mandatory: Use or
git rm <path>.git rm -r <path> - Rationale: Synchronously removes files from both the working directory and index, avoiding residual untracked deletion changes.
3. 操作前自检流程
3. Pre-Operation Self-Check Process
当 Agent 准备操作文件时,应遵循以下逻辑:
- 检查状态:执行 。
git ls-files <path> - 判断:
- 如果有输出(说明文件受控)→ 使用 /
git mv。git rm - 如果无输出(说明是未跟踪文件)→ 使用普通 /
mv。rm
- 如果有输出(说明文件受控)→ 使用
When an Agent is preparing to operate on files, it should follow this logic:
- Check Status: Execute .
git ls-files <path> - Judgment:
- If there is output (indicating the file is tracked) → Use /
git mv.git rm - If there is no output (indicating the file is untracked) → Use regular /
mv.rm
- If there is output (indicating the file is tracked) → Use
适用场景
Applicable Scenarios
- 重构代码导致的文件目录结构调整。
- 删除过时的文档或代码文件。
- 项目清理。
- Adjustments to file directory structure due to code refactoring.
- Deleting outdated documentation or code files.
- Project cleanup.
约束
Constraints
- 严禁在未确认文件状态的情况下盲目使用普通文件管理命令。
- 在执行大规模移动操作前,建议先执行 确保工作区是干净的。
git status
- It is strictly forbidden to blindly use regular file management commands without confirming the file status.
- Before performing large-scale move operations, it is recommended to execute first to ensure the working directory is clean.
git status