commit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Commit Skill
Git 提交技能
Sensitive File Guard
敏感文件防护
Before staging, scan for sensitive patterns:
git status- ,
.env*,*.pem,*.key,*.p12*.pfx - ,
*.tfstate(with real values)*.tfvars - ,
credentials.json,serviceAccountKey.json*secret*
If a match is found:
- Append the missing pattern to and stage
.gitignore..gitignore - If already tracked, warn and suggest .
git rm --cached <file> - Never proceed with committing a sensitive file.
在暂存文件前,扫描输出以检查敏感文件模式:
git status- ,
.env*,*.pem,*.key,*.p12*.pfx - ,
*.tfstate(包含真实值的文件)*.tfvars - ,
credentials.json,serviceAccountKey.json*secret*
如果匹配到敏感文件:
- 将缺失的模式添加到并暂存
.gitignore。.gitignore - 若文件已被追踪,发出警告并建议执行。
git rm --cached <file> - 绝对不要提交敏感文件。
Smart Commit Workflow
智能提交工作流
1. Review & Sensitive File Guard
1. 审查与敏感文件防护
bash
git status
git diff
git diff --cached
git log --oneline -5Scan the output against the sensitive patterns above.
bash
git status
git diff
git diff --cached
git log --oneline -5对照上述敏感文件模式扫描命令输出。
2. Auto-stage tracked changes
2. 自动暂存已追踪文件的变更
bash
git add -uStage tracked modifications and deletions only. Review untracked files first and stage by name if appropriate.
bash
git add -u仅暂存已追踪文件的修改和删除。先审查未追踪文件,必要时按名称单独暂存。
3. Analyse for multi-concern splitting
3. 分析并拆分多关注点变更
Group changed files by directory or feature area. If changes span unrelated concerns (e.g. a bug fix and a new feature), split into separate commits automatically.
按目录或功能区域对变更文件分组。若变更涉及不相关的关注点(例如同时包含bug修复和新功能),自动拆分为独立的提交。
4. Generate commit message
4. 生成提交信息
- Infer type: ,
feat,fix,chore,docs,refactor,test.style - Infer scope from the primary directory or feature area.
- Subject line: imperative voice, under 72 characters.
- Body (optional): explain "why", not "what".
- 推断类型:,
feat,fix,chore,docs,refactor,test。style - 从主要目录或功能区域推断范围。
- 主题行:使用祈使语气,长度不超过72字符。
- 正文(可选):解释“原因”而非“内容”。
5. Commit via heredoc
5. 通过here-doc提交
bash
git commit -m "$(cat <<'EOF'
type(scope): subject line
Optional body.
Co-Authored-By: Claude <model> <noreply@anthropic.com>
EOF
)"Replace with the actual model name (e.g. , ).
<model>Opus 4.6Sonnet 4.6bash
git commit -m "$(cat <<'EOF'
type(scope): subject line
Optional body.
Co-Authored-By: Claude <model> <noreply@anthropic.com>
EOF
)"将替换为实际模型名称(例如, )。
<model>Opus 4.6Sonnet 4.66. Handle pre-commit hook failure
6. 处理提交前钩子失败
Fix the issue, re-stage, and create a new commit. Never use . Never amend — the failed commit does not exist.
--no-verify修复问题,重新暂存,然后创建新的提交。绝对不要使用。绝对不要修改提交 —— 失败的提交视为不存在。
--no-verifyWorktree Workflow
Git Worktree 工作流
When working in a git worktree ():
.claude/worktrees/<name>/- Smart commit all changes using the workflow above.
- Switch to in the primary working directory.
main - Squash-merge: .
git merge --squash <worktree-branch> - Commit the squashed result with a single well-formed message.
- Verify: .
git log --oneline -5 && git status - Remove: .
git worktree remove .claude/worktrees/<name>
Commit before merging, always merge into , never delete the branch before merge is confirmed, use for linear history.
main--squash在git worktree()中工作时:
.claude/worktrees/<name>/- 使用上述工作流智能提交所有变更。
- 在主工作目录切换到分支。
main - Squash合并:。
git merge --squash <worktree-branch> - 使用格式规范的单一提交信息提交squash后的结果。
- 验证:。
git log --oneline -5 && git status - 移除工作树:。
git worktree remove .claude/worktrees/<name>
合并前需提交所有变更,始终合并到分支,确认合并完成前不要删除分支,使用以保持线性提交历史。
main--squashRules
规则
- Proceed without confirmation — stage, generate message, and commit in one flow.
- Never commit sensitive files (run the guard first).
- Never amend a published commit — create a new one.
- Never force-push .
main - Never use or
--no-verify.--no-gpg-sign - Prefer named files over to avoid staging secrets or noise.
git add -A
- 无需确认即可执行 —— 一次性完成暂存、生成提交信息和提交操作。
- 绝对不要提交敏感文件(先执行防护检查)。
- 绝对不要修改已发布的提交 —— 创建新的提交。
- 绝对不要强制推送分支。
main - 绝对不要使用或
--no-verify。--no-gpg-sign - 优先按名称指定文件而非使用,以避免暂存敏感信息或无关文件。
git add -A
Quick Reference
快速参考
- Sensitive File Guard → → multi-concern split → Conventional Commit via heredoc with
git add -u.Co-Authored-By - Worktree: commit → squash-merge to main → verify → remove.
- 敏感文件防护 → → 多关注点拆分 → 通过here-doc生成包含
git add -u的规范化提交。Co-Authored-By - Worktree流程:提交 → Squash合并到main → 验证 → 移除工作树。