git-commit-series
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Commit Series
Git 提交序列
Use this skill after the user explicitly invokes it to turn a mixed or large
change into a coherent commit series, or to reorganize local commits. It is a
planning and controlled-execution workflow, not a generic Git tutorial or a
single commit-message writer.
当用户明确调用此技能时,可将混合的大型变更转换为连贯的提交序列,或重新组织本地提交。这是一个规划与受控执行的工作流,而非通用Git教程或单一提交消息生成工具。
Modes and authorization
模式与授权
Choose one mode before reading the diff:
- plan (default): analyze the current worktree and produce a CommitPlan.
- execute: apply an approved plan one commit at a time.
- history-edit: split, reorder, squash, or otherwise rewrite existing local commits. Read references/history-surgery.md only for this mode.
Planning always comes first. Execution authorization must identify this plan
and either exact commit IDs or the complete resolved series; it never includes
undecided items. A request to organize, review, or propose commits
authorizes analysis only. Pushes, force-pushes, and changes outside the named
scope need separate confirmation.
If a baseline drift causes a revised plan, obtain authorization again for the
revised plan and exact IDs. If no matching handoff exists, stay in plan mode
even when the user asks to execute immediately.
In plan mode, keep Git refs, the index, and tracked files unchanged. If the
worktree or task scope changes after a plan, establish a new baseline before
executing it.
在查看差异前选择一种模式:
- plan(默认):分析当前工作区并生成CommitPlan。
- execute:逐次应用已批准的计划,生成提交。
- history-edit:拆分、重排、合并或以其他方式改写现有本地提交。仅在此模式下阅读references/history-surgery.md。
规划始终是第一步。执行授权必须明确指定该计划,以及确切的提交ID或完整的已解析序列;不得包含未确定项。组织、审核或提议提交的请求仅授权进行分析。推送、强制推送以及指定范围外的变更需要单独确认。
如果基线偏移导致计划修订,需针对修订后的计划和确切ID重新获取授权。如果没有匹配的交接信息,即使用户要求立即执行,也应保持在规划模式。
在plan模式下,保持Git引用、索引和已跟踪文件不变。如果规划后工作区或任务范围发生变化,需在执行前建立新的基线。
Invariants
不变量
Keep these leading words visible while working:
- baseline — the starting HEAD, index, worktree, and protected changes.
- hunk ledger — the complete accounting of every observed diff hunk.
- intent — the one logical reason for a commit.
- DAG — dependency edges between intents, later topologically ordered as a series.
- green gate — the checks that make a candidate commit understandable and verifiable.
- handoff — the stable plan another agent can execute without guessing.
- residual — changes intentionally left outside the series.
The series is correct only when every observed hunk has exactly one disposition,
every commit has one primary intent, dependencies are acyclic, protected
changes stay protected, and each public commit has an explicit validation
state. The smallest useful unit is a complete logical change, not a file,
directory, or line-count quota.
工作时需时刻关注以下核心概念:
- baseline —— 初始HEAD、索引、工作区以及受保护的变更。
- hunk ledger —— 所有已观察到的差异块的完整记录。
- intent —— 一次提交的单一逻辑原因。
- DAG —— 意图之间的依赖边,后续将按拓扑排序为series(序列)。
- green gate —— 使候选提交可理解、可验证的检查项。
- handoff —— 可供其他Agent无需猜测即可执行的稳定计划。
- residual —— 有意排除在序列之外的变更。
只有当每个观察到的差异块都有且仅有一个处置方式、每个提交都有一个主要意图、依赖关系无环、受保护变更保持不变,且每个公开提交都有明确的验证状态时,序列才是正确的。最小的有用单元是完整的逻辑变更,而非文件、目录或行数配额。
Workflow
工作流
1. Establish the baseline
1. 建立基线
- Locate the repository root, current branch or detached HEAD, intended base ref, and any merge/rebase policy. If no explicit base is supplied and no upstream is available, use the current HEAD only as a clearly recorded assumption; if more than one base is plausible, create a blocking decision. If the directory is not a Git repository, stop with a bounded explanation; if the repository has no commit yet, require an explicit base or report that a commit series cannot be anchored to a parent.
- Read repository-local instructions and sources of truth in this order: AGENTS.md/CLAUDE.md, contribution docs, commit hooks or lint configuration, package/build scripts, CI definitions, and recent history.
- Capture one read-only snapshot of branch, HEAD, index status, worktree status, staged and unstaged patches, untracked paths, and the relevant base..HEAD history. If there are no task-owned changes, report an empty series and the protected/residual state instead of inventing a commit. Normalize mixed staged and unstaged changes against their correct parents, then use the combined HEAD view to detect overlap; do not treat two diff views as one hunk stream.
- Classify changes as task-owned candidates, protected, excluded, undecided,
or residual. A task-owned candidate receives the disposition only after it is assigned to a series item. Use an explicit pre-task snapshot or the conversation as ownership evidence. If the base or ownership boundary has more than one plausible interpretation, place the affected changes in the undecided bucket and create a blocking decision; do not silently produce an executable plan. Keep the five dispositions disjoint. An undecided hunk belongs in the undecided ledger bucket and blocks execution until resolved.
commit
Done when: the rule sources, base SHA, baseline state, and a disjoint
disposition for every visible hunk are recorded; blocking ambiguity is surfaced.
- 定位仓库根目录、当前分支或分离HEAD、目标基准引用以及任何合并/变基策略。如果未提供明确基准且无上游可用,仅将当前HEAD作为明确记录的假设使用;如果存在多个合理基准,需发起阻塞性决策。如果目录不是Git仓库,需停止操作并给出明确解释;如果仓库尚无提交,需要求明确基准或说明提交序列无法锚定到父提交。
- 按以下顺序读取仓库本地的指令和可信来源:AGENTS.md/CLAUDE.md、贡献文档、提交钩子或lint配置、打包/构建脚本、CI定义以及近期提交历史。
- 捕获分支、HEAD、索引状态、工作区状态、已暂存和未暂存补丁、未跟踪路径以及相关base..HEAD历史的只读快照。如果没有任务相关的变更,需报告空序列以及受保护/剩余状态,而非凭空创建提交。针对正确的父提交规范化混合的已暂存和未暂存变更,然后使用合并后的HEAD视图检测重叠;不得将两个差异视图视为单一差异块流。
- 将变更分类为任务相关候选、受保护、排除、未确定或剩余。任务相关候选只有在被分配到序列项后才会被标记为处置方式。使用明确的任务前快照或对话作为所有权证据。 如果基准或所有权边界存在多种合理解释,需将受影响的变更放入未确定桶并发起阻塞性决策;不得静默生成可执行计划。 保持五种处置方式互斥。未确定的差异块属于未确定分类账桶,需解决后才能执行。
commit
完成标志: 已记录规则来源、基准SHA、基线状态以及每个可见差异块的互斥处置方式;已暴露阻塞性歧义。
2. Build the hunk ledger
2. 构建差异块分类账
Read boundary-rules.md when assigning ownership.
Inspect the complete diff, enabling rename detection when useful. Include
untracked files, renames, binary files, generated artifacts, and lockfiles.
Read untracked content explicitly (the default tracked-file diff omits it),
and represent an untracked file as a whole-file hunk when finer ownership is
impossible.
For each hunk, record its stable ID, path, old/new line anchor, short context
or patch fingerprint, concise summary, intent, behavior impact, direct tests,
dependencies, validation, rollback effect, and classifications such as
formatting, generated, lockfile, debug, or WIP. Merge coupled hunks when
separating them would create an unreviewable or unbuildable state.
Done when: every observed hunk appears exactly once across candidate
groups, protected, excluded, undecided, or residual buckets.
分配所有权时阅读boundary-rules.md。检查完整差异,必要时启用重命名检测。包括未跟踪文件、重命名、二进制文件、生成的工件和锁文件。明确读取未跟踪内容(默认已跟踪文件差异会省略这些内容),当无法细分所有权时,将未跟踪文件表示为完整文件差异块。
对于每个差异块,记录其稳定ID、路径、旧/新行锚点、简短上下文或补丁指纹、简明摘要、意图、行为影响、直接测试、依赖关系、验证、回滚效果以及格式化、生成、锁文件、调试或WIP等分类。当拆分耦合的差异块会导致无法审核或无法构建的状态时,需合并这些差异块。
完成标志: 每个观察到的差异块都恰好出现在候选组、受保护、排除、未确定或剩余桶中。
3. Form atomic intents and the dependency DAG
3. 形成原子意图与依赖DAG
Cluster by intent, coupling, review boundary, and rollback boundary. Keep
behavior and its directly coupled tests together. Give independent mechanical
refactors, formatting, documentation, dependency maintenance, and unrelated
cleanup their own intent when they can stand alone. Keep a cross-file change
together when it expresses one logical change. Follow real migration
dependencies (for example, expand/compatibility layer → callers → contract or
cleanup), and follow the repository's rules for lockfiles and generated output.
Do not let a message type such as feat, fix, or refactor decide the boundary.
Prefer a green series: each public point should build and pass the smallest
relevant checks. A necessarily red intermediate state belongs in local fixup
work, or is called out as an explicit repository-approved exception.
Create one directed edge for each required predecessor, detect cycles, and
topologically sort the result into C1…Cn. Read the boundary reference again
for migration, generated-file, lockfile, or inseparable-hunk cases.
Done when: the candidate groups cover the ledger without overlap, each
group has one sentence-level intent, the DAG has no cycle, and the sorted
series is minimal but complete.
按意图、耦合性、审核边界和回滚边界进行聚类。将行为及其直接耦合的测试放在一起。当独立的机械重构、格式化、文档更新、依赖维护和无关清理可独立存在时,为其分配单独的意图。当跨文件变更表达单一逻辑变更时,需将其放在一起。遵循实际的迁移依赖关系(例如,扩展/兼容层 → 调用方 → 契约或清理),并遵循仓库关于锁文件和生成输出的规则。
不要让feat、fix或refactor等消息类型决定边界。优先选择“绿色”序列:每个公开节点都应能构建并通过最小相关检查。必要的“红色”中间状态应属于本地修复工作,或被明确标记为仓库批准的例外情况。
为每个必需的前置项创建一条有向边,检测循环,并将结果拓扑排序为C1…Cn。对于迁移、生成文件、锁文件或不可拆分差异块的情况,再次阅读边界参考文档。
完成标志: 候选组无重叠地覆盖分类账,每个组都有一个句子级别的意图,DAG无循环,排序后的序列最小且完整。
4. Apply the green gate
4. 应用绿色检查门
Discover validation commands from the repository rather than copying a generic
command list. In plan mode, run only known read-only checks. Materialize a
candidate with a disposable filesystem copy before a build or test that could
create tracked or untracked artifacts; keep the source repository unchanged. A
may change repository metadata, so use it only with explicit
permission. If the executable or test entry point is unavailable, mark the gate
not-run and name the missing prerequisite; reserve failed for a command that
actually ran and failed.
Select a focused check for each candidate, add broader checks where policy
requires them, and include git diff --check when applicable. Mark every check
pending, passed, failed, or not-run; an unrun check is never a pass.
git worktree addCheck that each candidate can be reviewed and reverted on its own, that
debug/WIP material is accounted for, and that the proposed message follows the
repository's actual convention. Use a Conventional Commits shape only as a
fallback when no local convention exists.
Done when: every candidate has a command, purpose, expected result, current
validation state, and a recorded explanation for anything not run.
从仓库中发现验证命令,而非复制通用命令列表。在规划模式下,仅运行已知的只读检查。在可能创建已跟踪或未跟踪工件的构建或测试前,使用一次性文件系统副本实例化候选提交;保持源仓库不变。可能会更改仓库元数据,因此仅在获得明确许可时使用。如果可执行文件或测试入口不可用,标记检查门为未运行并说明缺失的先决条件;仅当命令实际运行并失败时才标记为失败。
为每个候选提交选择针对性检查,在策略要求时添加更广泛的检查,并在适用时包含git diff --check。标记每个检查为待处理、通过、失败或未运行;未运行的检查永远不算通过。
git worktree add检查每个候选提交是否可独立审核和回滚,是否已说明调试/WIP内容,以及提议的消息是否符合仓库的实际约定。仅当本地无约定时,才以Conventional Commits格式作为 fallback。
完成标志: 每个候选提交都有命令、目的、预期结果、当前验证状态,以及任何未运行项的记录说明。
5. Produce the handoff
5. 生成交接文档
Read plan-schema.md for the authoritative fields
and output-template.md for the presentation
contract. Output the schema version, base and baseline, protected, excluded,
undecided, and residual changes, the dependency order, and each commit's
operation, subject/body, intent, exact hunk ownership, dependencies,
validation gates, risk, rollback, and status. List open decisions instead of
silently choosing across an unresolved boundary.
In plan mode, stop after this handoff. The handoff is complete when another
agent can stage exactly one planned commit at a time without inferring where a
hunk belongs.
生成交接文档前阅读plan-schema.md(权威字段)和output-template.md(呈现规范)。输出 schema 版本、基准和基线、受保护、排除、未确定和剩余变更、依赖顺序,以及每个提交的操作、主题/正文、意图、确切差异块所有权、依赖关系、验证检查门、风险、回滚和状态。列出未解决的决策,而非在未解决的边界上静默选择。
在规划模式下,完成此交接后停止操作。当其他Agent无需推断差异块归属即可逐次暂存一个计划提交时,交接即完成。
6. Execute only an approved handoff
6. 仅执行已批准的交接计划
After explicit authorization, read
execution-safety.md. Recheck the baseline,
confirm the authorization covers the exact resolved IDs, then use path- or
hunk-scoped staging, inspect the cached diff, run that commit's green gate, and
create exactly one commit before moving to the next.
If the actual diff no longer matches the plan, pause and re-plan. For
history-edit mode, also read history-surgery.md.
Done when: every authorized plan item has one recorded commit result and no
protected change was staged or rewritten.
获得明确授权后,阅读execution-safety.md。重新检查基线,确认授权涵盖确切的已解析ID,然后使用路径或差异块范围的暂存操作,检查缓存的差异,运行该提交的绿色检查门,创建一个提交后再进行下一个。
如果实际差异与计划不再匹配,暂停并重新规划。对于history-edit模式,还需阅读history-surgery.md。
完成标志: 每个已授权的计划项都有一个记录的提交结果,且未暂存或改写任何受保护变更。
7. Audit the result
7. 审核结果
Compare the actual series with the handoff using commit log inspection,
base..HEAD diff review, and range-diff when history was rewritten. Recheck
status, protected changes, residual paths, and every validation result. Report
hashes and deviations; distinguish passed, failed, not-run, and blocked.
Done when: the final report accounts for every planned item, every
residual change, and every mutation made.
通过提交日志检查、base..HEAD差异审核以及改写历史时的range-diff,将实际序列与交接文档进行比较。重新检查状态、受保护变更、剩余路径以及每个验证结果。报告哈希值和偏差;区分通过、失败、未运行和阻塞状态。
完成标志: 最终报告涵盖了所有计划项、所有剩余变更以及所有已执行的修改。
Conditional references
条件参考文档
- Read references/boundary-rules.md during hunk classification and whenever a change mixes behavior, tests, refactoring, migration, generated output, lockfiles, or WIP.
- Read references/plan-schema.md and references/output-template.md before producing the handoff.
- Read references/execution-safety.md only after execution is authorized.
- Read references/history-surgery.md only when existing commit history will be rewritten.
- 在差异块分类期间,以及当变更混合了行为、测试、重构、迁移、生成输出、锁文件或WIP时,阅读references/boundary-rules.md。
- 生成交接文档前,阅读references/plan-schema.md和references/output-template.md。
- 仅在执行获得授权后,阅读references/execution-safety.md。
- 仅当需要改写现有提交历史时,阅读references/history-surgery.md。