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. 通过here-doc提交

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. 处理提交前钩子失败

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

Worktree Workflow

Git Worktree 工作流

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 worktree(
.claude/worktrees/<name>/
)中工作时:
  1. 使用上述工作流智能提交所有变更。
  2. 在主工作目录切换到
    main
    分支。
  3. Squash合并
    git merge --squash <worktree-branch>
  4. 使用格式规范的单一提交信息提交squash后的结果。
  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.
  • 无需确认即可执行 —— 一次性完成暂存、生成提交信息和提交操作。
  • 绝对不要提交敏感文件(先执行防护检查)。
  • 绝对不要修改已发布的提交 —— 创建新的提交。
  • 绝对不要强制推送
    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
    → 多关注点拆分 → 通过here-doc生成包含
    Co-Authored-By
    的规范化提交。
  • Worktree流程:提交 → Squash合并到main → 验证 → 移除工作树。