git-commit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Commit Skill

Git提交技能

Sensitive File Guard

敏感文件防护

Before staging, scan
git status
for sensitive patterns:
  • .env*
    ,
    *.pem
    ,
    *.key
    ,
    *.p12
    ,
    *.pfx
  • *.tfstate
    ,
    *.tfvars
    (with real values)
  • credentials.json
    ,
    serviceAccountKey.json
    ,
    *secret*
If a match is found:
  1. Append the missing pattern to
    .gitignore
    and stage
    .gitignore
    .
  2. If already tracked, warn and suggest
    git rm --cached <file>
    .
  3. Never proceed with committing a sensitive file.
暂存前扫描
git status
的输出,查找敏感文件模式:
  • .env*
    ,
    *.pem
    ,
    *.key
    ,
    *.p12
    ,
    *.pfx
  • 包含真实值的
    *.tfstate
    ,
    *.tfvars
  • credentials.json
    ,
    serviceAccountKey.json
    , 名称含
    secret
    的所有文件
如果匹配到敏感文件:
  1. 将缺失的匹配规则追加到
    .gitignore
    并暂存
    .gitignore
    文件
  2. 如果文件已被追踪,发出警告并建议执行
    git rm --cached <file>
    命令
  3. 绝对不要提交敏感文件

Smart Commit Workflow

智能提交流程

1. Review & Sensitive File Guard

1. 代码审查与敏感文件防护

bash
git status
git diff
git diff --cached
git log --oneline -5
Scan 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 -u
Stage 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. 通过heredoc提交

bash
git commit -m "$(cat <<'EOF'
type(scope): subject line

Optional body.

Co-Authored-By: Claude <model> <noreply@anthropic.com>
EOF
)"
Replace
<model>
with the actual model name (e.g.
Opus 4.6
,
Sonnet 4.6
).
bash
git commit -m "$(cat <<'EOF'
type(scope): subject line

Optional body.

Co-Authored-By: Claude <model> <noreply@anthropic.com>
EOF
)"
<model>
替换为实际使用的模型名称(例如
Opus 4.6
,
Sonnet 4.6
)。

6. Handle pre-commit hook failure

6. 处理pre-commit钩子失败

Fix the issue, re-stage, and create a new commit. Never use
--no-verify
. Never amend — the failed commit does not exist.
修复问题,重新暂存,然后创建新的提交。绝对不要使用
--no-verify
参数,也不要执行amend操作——提交失败的提交本身不存在。

Worktree Workflow

工作树工作流

When working in a git worktree (
.claude/worktrees/<name>/
):
  1. Smart commit all changes using the workflow above.
  2. Switch to
    main
    in the primary working directory.
  3. Squash-merge:
    git merge --squash <worktree-branch>
    .
  4. Commit the squashed result with a single well-formed message.
  5. Verify:
    git log --oneline -5 && git status
    .
  6. Remove:
    git worktree remove .claude/worktrees/<name>
    .
Commit before merging, always merge into
main
, never delete the branch before merge is confirmed, use
--squash
for linear history.
当在git工作树(
.claude/worktrees/<name>/
)中工作时:
  1. 使用上述流程对所有变更执行智能提交
  2. 在主工作目录中切换到
    main
    分支
  3. 压缩合并:执行
    git merge --squash <worktree-branch>
    命令
  4. 为压缩后的结果提交一条格式规范的提交信息
  5. 验证:执行
    git log --oneline -5 && git status
    检查
  6. 移除工作树:执行
    git worktree remove .claude/worktrees/<name>
始终在合并前先提交,所有合并目标均为
main
分支,在合并确认完成前绝对不要删除分支,使用
--squash
参数保持提交历史线性。

Rules

规则

  • 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
    --no-verify
    or
    --no-gpg-sign
    .
  • Prefer named files over
    git add -A
    to avoid staging secrets or noise.
  • 无需确认即可执行:暂存、生成信息、提交一步完成
  • 绝对不要提交敏感文件(必须先运行防护检查)
  • 绝对不要amend已推送的提交——创建新提交即可
  • 绝对不要强制推送
    main
    分支
  • 绝对不要使用
    --no-verify
    --no-gpg-sign
    参数
  • 优先按文件名暂存,避免使用
    git add -A
    ,防止误提交密钥或无关文件

Quick Reference

快速参考

  • Sensitive File Guard →
    git add -u
    → multi-concern split → Conventional Commit via heredoc with
    Co-Authored-By
    .
  • Worktree: commit → squash-merge to main → verify → remove.
  • 敏感文件防护 →
    git add -u
    → 多关注点拆分 → 通过heredoc生成包含
    Co-Authored-By
    的约定式提交
  • 工作树流程:提交 → 压缩合并到main分支 → 验证 → 移除