commit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCommit
提交
Analyze uncommitted changes and create well-organized commits using conventional commit format.
分析未提交的变更,并使用规范式提交(conventional commit)格式创建结构清晰的提交。
Workflow
工作流程
1. Discover Changes
1. 发现变更
Current repo state (injected at invocation — no tool calls needed):
- Status: !
git status --porcelain - Diff stats: !
git diff --stat
Abort before staging if any apply:
- Not a git repository.
- No changes ("Nothing to commit").
- Mid-merge / rebase / cherry-pick / revert — would stage conflict markers as content. Check
git add -Afor$(git rev-parse --git-dir),MERGE_HEAD,CHERRY_PICK_HEAD,REVERT_HEAD, orrebase-merge/. If any present, report the in-progress operation and stop.rebase-apply/ - Detached HEAD — is empty. Commit would land on an unreferenced commit and be lost on branch switch. Report and stop.
git symbolic-ref -q HEAD
当前仓库状态(调用时注入——无需工具调用):
- 状态:!
git status --porcelain - 差异统计:!
git diff --stat
如果出现以下任一情况,在暂存前终止操作:
- 不是Git仓库。
- 无变更("Nothing to commit")。
- 处于合并/变基/拣选/回退过程中——会将冲突标记作为内容暂存。检查
git add -A是否存在$(git rev-parse --git-dir)、MERGE_HEAD、CHERRY_PICK_HEAD、REVERT_HEAD或rebase-merge/。如果存在任何一项,报告正在进行的操作并停止。rebase-apply/ - 处于分离HEAD状态——为空。提交会落在未被引用的提交上,切换分支时会丢失。报告此情况并停止。
git symbolic-ref -q HEAD
2. Stage Files
2. 暂存文件
Run to stage all changes.
git add -AExclude generated or ephemeral files that should never be version-controlled: , , , , , , , , , .
scratch.*temp.*debug.*playground.**.logdist/build/target/node_modules/__pycache__/If such files detected:
- Unstage with
git reset HEAD <file> - Ask user if they want to add to .gitignore
Proceed when all intended files are staged and ephemeral files are excluded.
执行暂存所有变更。
git add -A排除不应被版本控制的生成文件或临时文件:、、、、、、、、、。
scratch.*temp.*debug.*playground.**.logdist/build/target/node_modules/__pycache__/如果检测到此类文件:
- 使用取消暂存
git reset HEAD <file> - 询问用户是否要将其添加到.gitignore中
当所有目标文件已暂存且临时文件已排除后,继续操作。
3. Analyze Commit Boundaries
3. 分析提交边界
For each changed file, write a one-line PURPOSE description (not file location).
Group by PURPOSE, not directory:
- Same goal = one commit
- Different goals = separate commits
Each commit should represent one logical change because atomic commits enable and without side-effects.
git bisectgit revertSigns of separate concerns:
- "Added X" AND "Fixed Y" (feature + bugfix)
- Changes that could be reverted independently
- Different conventional-commit types on related work — a fix and its tests go in separate and
fix:commits so the fix can be reverted without losing the teststest:
If multiple concerns: use then for each group. Commit foundational changes first.
git reset HEADgit add <specific-files>Handle renames (R status): When splitting, add BOTH old and new paths. Git detects renames by similarity scoring across the old/new pair — staging only the new path causes git to log a delete + add, losing rename history.
Proceed when every changed file is assigned to exactly one commit group.
对每个变更文件,编写一行用途描述(而非文件位置)。
按用途分组,而非按目录分组:
- 同一目标 = 一次提交
- 不同目标 = 分开提交
每次提交应代表一个逻辑变更,因为原子提交支持和且无副作用。
git bisectgit revert需分开处理的迹象:
- "添加了X"且"修复了Y"(功能+ bug修复)
- 可独立回退的变更
- 相关工作使用不同的规范式提交类型——修复代码与其测试应分别放在和
fix:提交中,以便回退修复时不会丢失测试test:
如果存在多个关注点:使用,然后对每组文件执行。优先提交基础变更。
git reset HEADgit add <specific-files>处理重命名(R状态):拆分提交时,同时添加旧路径和新路径。Git通过新旧文件对的相似度评分检测重命名——仅暂存新路径会导致Git记录为删除+添加,丢失重命名历史。
当每个变更文件都被分配到恰好一个提交组后,继续操作。
4. Validate
4. 验证
Run the validation script after staging:
bash
python3 ${CLAUDE_PLUGIN_ROOT}/skills/commit/scripts/validate.py . --output jsonInterpret the result:
- Exit 0 → validation passed; proceed to Step 5
- Exit 1 → validation failed; parse the field, report the error to the user, and stop
output - Exit 2 → validator skipped (no marker file, no staged files match the validator's extensions, or the tool isn't installed); proceed to Step 5. The field names the reason.
output
暂存后执行验证脚本:
bash
python3 ${CLAUDE_PLUGIN_ROOT}/skills/commit/scripts/validate.py . --output json解读结果:
- 退出码0 → 验证通过;进入步骤5
- 退出码1 → 验证失败;解析字段,向用户报告错误并停止
output - 退出码2 → 验证器跳过(无标记文件、无暂存文件匹配验证器的扩展名,或工具未安装);进入步骤5。字段会说明原因。
output
5. Create Commit
5. 创建提交
Check recent commit style:
bash
git log --no-merges --oneline -10Use conventional commit format:
<type>(<scope>): <description>Types: feat, fix, docs, refactor, test, chore, perf
- Lowercase subject, no period, imperative mood
- Max 72 chars for subject
- Omit Co-authored-by trailers and AI attribution — these pollute and break downstream tooling that greps commit metadata
git log - No emojis
If fails due to a pre-commit hook: the commit did NOT land. Check — the hook may have auto-fixed files (e.g. syncing ) and left them modified. Re-stage () and retry the same command with the same message. Do NOT use (amends the PREVIOUS commit, not the failed one). Do NOT use (skips the hook entirely, defeating its guard).
git commitgit statusauto-version.pyplugin.jsongit add -Agit commit--amend--no-verifyProceed when the commit message is drafted and matches the repo's existing style.
查看近期提交风格:
bash
git log --no-merges --oneline -10使用规范式提交格式:
<type>(<scope>): <description>类型:feat、fix、docs、refactor、test、chore、perf
- 主题使用小写,无句号,采用祈使语气
- 主题最大72字符
- 省略Co-authored-by尾部信息和AI归因——这些会污染并破坏依赖提交元数据的下游工具
git log - 不使用表情符号
如果因预提交钩子失败:提交未成功完成。检查——钩子可能自动修复了文件(例如同步)并留下未暂存的修改。重新暂存()并使用相同的提交信息重试命令。不要使用(会修改上一次提交,而非失败的提交)。不要使用(会完全跳过钩子,失去其防护作用)。
git commitgit statusauto-version.pyplugin.jsongit add -Agit commit--amend--no-verify当提交信息已草拟并匹配仓库现有风格后,继续操作。
6. Push (only if requested)
6. 推送(仅在请求时执行)
If user mentions "push" or arguments contain "push", run . If push fails, report the error and stop — do not retry or force-push.
git push如果用户提及“push”或参数包含“push”,执行。如果推送失败,报告错误并停止——不要重试或强制推送。
git pushOutput
输出
One line per commit (hash + message). If temporary files were excluded, list them as bullets below.
每个提交一行(哈希值 + 提交信息)。如果排除了临时文件,在下方以项目符号列表列出这些文件。