my-curate-git-history
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese重组本地提交历史
Restructure Local Commit History
把一段连续、尚未集成的本地开发提交重建为少量可理解的提交,同时保持最终 tree 不变。典型场景是 AI 产生了大量交错的 fix、补漏和机械提交,需要按最终文件内容重新归组,而不是机械 squash 旧 commit。
Reconstruct a continuous segment of unintegrated local development commits into a small number of understandable commits while keeping the final tree unchanged. A typical scenario is when AI generates a large number of interleaved fixes, patches, and mechanical commits, which need to be regrouped based on the final file content instead of mechanically squashing old commits.
授权与边界
Authorization and Boundaries
- 用户明确调用本 skill 或要求 recommit / 重写历史,即授权重写已确认范围内的本地历史;只要求分析或建议时保持只读。
- 默认目标分支为当前分支、目标端点为操作前的 、基线为本地
HEAD。若upstream/main不存在,使用用户明确给出的基线;两者都没有时必须询问,不得擅自改用upstream/main、共同祖先或猜测的 hash。origin/main - 只重写尚未集成的本地提交。若目标提交已进入基线、其他共享分支或已发布历史,先说明影响并取得明确确认。
- 不 fetch、pull、push、创建 PR 或更新远端。发布重写后的分支是另一项操作,通常需要用户另行授权 。
--force-with-lease - 不修改 submodule 内部历史或工作区。父仓库 gitlink 只有在目标最终 tree 本来就包含其变化时才可纳入。
- When the user explicitly calls this skill or requests to recommit / rewrite history, it authorizes rewriting the local history within the confirmed scope; maintain read-only mode when only analysis or suggestions are requested.
- The default target branch is the current branch, the target endpoint is before the operation, and the baseline is local
HEAD. Ifupstream/maindoes not exist, use the baseline explicitly provided by the user; if neither exists, you must ask and must not arbitrarily switch toupstream/main, common ancestor or guessed hash.origin/main - Only rewrite unintegrated local commits. If the target commits have been merged into the baseline, other shared branches or published history, first explain the impact and obtain explicit confirmation.
- Do not fetch, pull, push, create PR or update remote endpoints. Publishing the rewritten branch is a separate operation, which usually requires the user to authorize separately.
--force-with-lease - Do not modify the internal history or workspace of submodules. The parent repository gitlink can only be included if the target final tree originally contains its changes.
动手前确认
Pre-Operation Confirmation
一次性收集并判断:
- 仓库根、当前分支、、基线解析结果、
HEAD。git status --short --branch - 的提交数、拓扑、提交信息、每个提交的 author/committer 日期与时区、文件变化和最终 diff。
base..HEAD - 基线是否为 的祖先,范围内是否含 merge、签名提交、多作者历史,目标提交是否被其他本地或远端跟踪分支包含。
HEAD - submodule/gitlink 状态,以及仓库指令要求的检查。
根工作树或 index 有既存改动时停止,避免 reset 将用户现场与待重建内容混在一起。存在下列情况也先询问:
- 基线不是旧 的祖先;这已从整理连续历史变成把最终 tree 移植到另一基线。
HEAD - 用户只泛称“整理历史”但范围含 merge,需要决定是否允许扁平化拓扑;若用户已明确要求 reset 后按文件 recommit,则该范围内的扁平化已获授权,但仍要报告会丢失的 merge 拓扑。
- 已发布、已签名或多作者历史会丢失签名、拓扑或准确归属。
- 无法在不显著破坏内容边界的情况下接近目标提交数。
条件明确后,先保存:
- 旧 的 hash 与 tree hash。
HEAD - 唯一、易识别的本地恢复 branch 或 tag,例如 ;这里的当前时间只用于恢复引用命名,不得用于 commit 日期。
backup/<branch>-before-recommit-<timestamp> - 操作前 status、分支包含关系和 submodule 状态,供结束时核对。
恢复引用创建成功前不得 reset。
Collect and judge at one time:
- Repository root, current branch, , baseline parsing result,
HEAD.git status --short --branch - Number of commits, topology, commit messages, author/committer dates and timezones of each commit, file changes and final diff in the range .
base..HEAD - Whether the baseline is an ancestor of , whether the range includes merge, signed commits, multi-author history, and whether the target commits are included in other local or remote tracking branches.
HEAD - Submodule/gitlink status, and checks required by repository instructions.
Stop if there are existing changes in the root working tree or index, to avoid mixing the user's current state with the content to be reconstructed via reset. Also ask first in the following situations:
- The baseline is not an ancestor of the old ; this has changed from organizing continuous history to transplanting the final tree to another baseline.
HEAD - The user only generically refers to "organizing history" but the range includes merges, and needs to decide whether to allow flattening the topology; if the user has explicitly requested to reset and recommit by file, flattening within this scope is authorized, but the lost merge topology must still be reported.
- Published, signed or multi-author history will lose signatures, topology or accurate attribution.
- It is impossible to approach the target number of commits without significantly breaking content boundaries.
After clarifying the conditions, save first:
- The hash and tree hash of the old .
HEAD - A unique, easily identifiable local recovery branch or tag, such as ; the current time here is only used for naming the recovery reference, and must not be used for commit dates.
backup/<branch>-before-recommit-<timestamp> - Pre-operation status, branch inclusion relationship and submodule status, for verification at the end.
Do not reset until the recovery reference is successfully created.
设计新提交
Design New Commits
先完成分组再改写历史。依据是 的最终文件内容、历史 diff 和依赖关系,旧 commit message 只能作为线索。
base..old_HEAD- 用户未指定数量时,先以 作为规划目标。它不是强行为凑数的配额:若完整文件和清晰职责自然形成更少批次,可以继续压缩;若合理边界明显更多,则说明偏差,必要时询问。
max(1, round(原提交数 × 20%)) - 优先按可独立理解的功能、修复或配置闭环分组;实现、直接测试、必要 spec/文档和配套 lockfile 可放在同一提交。
- 默认一个文件只归入一个新提交,按完整路径暂存,不使用 patch staging。一个文件跨多个旧提交时,以它的最终版本归入最能解释其完整职责的批次。
- 重命名、删除、生成物、manifest/lockfile、迁移及 gitlink 要成对或随其真实依赖归组,不能只看扩展名机械分类。
- 只有完整文件归组会造成明显错误边界,且无法通过调整批次解决时,才考虑拆分同一文件;先向用户说明原因和最小拆分方案。
- 按依赖和读者理解顺序排列提交。不要为了复刻旧时间顺序而破坏内容边界,也不要声称未验证的中间提交可构建或可独立运行。
开始 reset 前应能列出每批的目的、完整路径集合、拟用提交信息及所选旧时间来源。范围清楚且用户已明确要求重写时直接继续;只有边界或数量存在实质歧义时才请求确认。
Complete grouping before rewriting history. The basis is the final file content, historical diff and dependency relationship of ; old commit messages can only be used as clues.
base..old_HEAD- If the user does not specify the number, first use as the planning target. It is not a rigid quota to force the count: if complete files and clear responsibilities naturally form fewer batches, you can continue to compress; if reasonable boundaries are obviously more, explain the deviation and ask if necessary.
max(1, round(original number of commits × 20%)) - Prioritize grouping by independently understandable functions, fixes or closed-loop configurations; implementation, direct testing, necessary spec/docs and supporting lockfiles can be placed in the same commit.
- By default, a file is only assigned to one new commit, staged by full path, and patch staging is not used. When a file spans multiple old commits, assign its final version to the batch that best explains its complete responsibility.
- Renaming, deletion, generated files, manifest/lockfiles, migrations and gitlinks should be grouped in pairs or with their actual dependencies, not mechanically classified by file extension.
- Only when grouping complete files will cause obvious wrong boundaries and cannot be solved by adjusting batches, consider splitting the same file; first explain the reason and the minimal splitting scheme to the user.
- Arrange commits in the order of dependencies and reader understanding. Do not break content boundaries to replicate the old time order, nor claim that unverified intermediate commits can be built or run independently.
Before starting reset, you should be able to list the purpose of each batch, complete path set, intended commit message and selected old time source. Continue directly when the scope is clear and the user has explicitly requested rewriting; only request confirmation when there is substantial ambiguity in boundaries or quantity.
重建提交
Reconstruct Commits
使用保留工作树最终内容的 reset 方式回到已确认基线;禁止 、、 或删除用户文件。
reset --hardcheckout --clean逐批执行:
- 只暂存本批明确列出的完整路径;删除和重命名也必须正确进入 index。
- 查看 和实际 staged diff,并运行
git diff --cached --name-status,确认没有遗漏、跨批次文件或 hook 产生的额外改动。git diff --cached --check - 从 staged 的真实内容生成简洁 commit message,遵循仓库现有约定;不得照抄与当前批次不符的旧 message,也不得声称未包含或未验证的内容。
- 从原始范围内挑选一个真实旧提交作为时间来源,逐字复用其完整 author date 和 committer date,包括秒、时区偏移。优先选择与该批主要文件或里程碑相关的记录;无法内容对应时,仍只能从原记录中选择,并使所选时间按新提交顺序合理递增。
- 用该原记录的 设置
author date,用其GIT_AUTHOR_DATE设置committer date后提交。不得使用当前时间、整点、取整、平均值、手工加减秒或其他捏造时间;不要把 author date 复制成原本不同的 committer date。GIT_COMMITTER_DATE
空提交默认丢弃。commit hook 若改写或生成文件,立即停止并重新核对,不自动把新内容混入下一批。
Use a reset method that retains the final content of the working tree to return to the confirmed baseline; prohibit , , or deleting user files.
reset --hardcheckout --cleanExecute batch by batch:
- Only stage the full paths explicitly listed in this batch; deletions and renames must also be correctly added to the index.
- Check and the actual staged diff, and run
git diff --cached --name-statusto confirm no omissions, cross-batch files or additional changes generated by hooks.git diff --cached --check - Generate a concise commit message from the real staged content, following the existing conventions of the repository; do not copy old messages that do not match the current batch, nor claim content that is not included or verified.
- Select a real old commit from the original scope as the time source, and reuse its complete author date and committer date verbatim, including seconds and timezone offset. Prioritize records related to the main files or milestones of this batch; if no content correspondence can be found, still only select from the original records, and ensure that the selected time increases reasonably in the order of new commits.
- Set with the original record's
GIT_AUTHOR_DATE, setauthor datewith itsGIT_COMMITTER_DATE, then commit. Do not use current time, whole hours, rounded values, averages, manual adjustment of seconds or other fabricated times; do not copy the author date as the originally different committer date.committer date
Empty commits are discarded by default. If a commit hook rewrites or generates files, stop immediately and recheck, do not automatically mix the new content into the next batch.
验证与交付
Verification and Delivery
完成后至少验证:
- 新 tree hash 与恢复引用保存的旧
HEADtree hash 完全相同;以 tree equality 为最终内容不变的硬门槛。HEAD - 工作树和 index 干净;操作前存在的 submodule 工作区状态未变化,最终 gitlink 与旧 tree 一致。
- 新提交数及其占原提交数的比例符合用户要求或已说明的合理偏差。
- 查看每个新提交的 、stat、message、author/committer 时间,确认时间值确实存在于原始范围。
name-status - 审核新范围内各路径的出现次数;除已明确批准的例外外,一个文件不跨多个新提交。
- 运行仓库强制检查和与最终内容直接相关的低成本验证。只有实际执行过,才能声称通过。
任一新 commit 失败或最终 tree 不一致时停止,不 push,不删除恢复引用。优先回到恢复引用重新设计分组,不用补丁提交掩盖错误。
最终报告基线、旧/新提交数、压缩比例、新提交 hash 与 subject、时间来源、tree equality、实际验证、恢复引用和剩余工作区状态。明确说明尚未 push;不要主动删除恢复引用。
After completion, verify at least the following:
- The tree hash of the new is exactly the same as the tree hash of the old
HEADsaved in the recovery reference; tree equality is the hard threshold for ensuring unchanged final content.HEAD - The working tree and index are clean; the submodule workspace status existing before the operation has not changed, and the final gitlink is consistent with the old tree.
- The number of new commits and its proportion to the original number of commits meet the user's requirements or the explained reasonable deviation.
- Check the , stat, message, author/committer time of each new commit, and confirm that the time values do exist in the original scope.
name-status - Audit the occurrence times of each path in the new scope; except for explicitly approved exceptions, a file should not span multiple new commits.
- Run the mandatory repository checks and low-cost verification directly related to the final content. Only after actual execution can you claim to have passed.
Stop if any new commit fails or the final tree is inconsistent, do not push, do not delete the recovery reference. Prioritize returning to the recovery reference to redesign grouping, do not cover up errors with patch commits.
Finally report the baseline, number of old/new commits, compression ratio, new commit hash and subject, time source, tree equality, actual verification, recovery reference and remaining workspace status. Clearly state that it has not been pushed; do not actively delete the recovery reference.