git-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,teststyle - 从主目录或功能模块推断范围
- 标题行:使用祈使语气,长度不超过72个字符
- 正文(可选):解释变更的「原因」而非「内容」
5. Commit via heredoc
5. 通过heredoc提交
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. 处理pre-commit钩子失败
Fix the issue, re-stage, and create a new commit. Never use . Never amend — the failed commit does not exist.
--no-verify修复问题,重新暂存,然后创建新的提交。绝对不要使用参数,也不要执行amend操作——提交失败的提交本身不存在。
--no-verifyWorktree Workflow
工作树工作流
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工作树()中工作时:
.claude/worktrees/<name>/- 使用上述流程对所有变更执行智能提交
- 在主工作目录中切换到分支
main - 压缩合并:执行命令
git merge --squash <worktree-branch> - 为压缩后的结果提交一条格式规范的提交信息
- 验证:执行检查
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
- 无需确认即可执行:暂存、生成信息、提交一步完成
- 绝对不要提交敏感文件(必须先运行防护检查)
- 绝对不要amend已推送的提交——创建新提交即可
- 绝对不要强制推送分支
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.
- 敏感文件防护 → → 多关注点拆分 → 通过heredoc生成包含
git add -u的约定式提交Co-Authored-By - 工作树流程:提交 → 压缩合并到main分支 → 验证 → 移除