一键导入
branch-archive-rechunk-rebase
Rewrite current branch into N semantic commits with a legacy backup branch and optional rebase onto origin/main.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Rewrite current branch into N semantic commits with a legacy backup branch and optional rebase onto origin/main.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Create, repair, validate, visually QA, and package Codex-compatible v2 animated pets from character art, generated images, company or prospect brand cues, or visual references. Use for any new Codex pet, custom mascot, non-pixel pet style, brand-inspired pet, existing-pet repair, or 8x11 spritesheet workflow requiring all 9 standard animation rows, 16 look directions, deterministic assembly, QA artifacts, and spriteVersionNumber 2 packaging.
Merge origin/main into current branch while preserving branch intent, context, and ownership decisions.
Chain branch onboarding, code-health, and non-test analysis into a branch-scoped remediation plan.
Summarize current branch diff from fork point with intent, scope, risks, and context for follow-on work.
Audit codebase architecture: module dependencies, layering, circular imports, ownership, and structural decay.
Assess tech debt and rank refactoring priorities, change pain, maintainability risks, and cleanup roadmap.
| name | branch-archive-rechunk-rebase |
| description | Rewrite current branch into N semantic commits with a legacy backup branch and optional rebase onto origin/main. |
Run a deterministic history-rewrite workflow for the current branch. Treat rechunking as semantic branch reconstruction: the goal is not to preserve or merely merge existing commits, but to rebuild the branch around the fragmented semantic changes that matter now. Collect onboarding context first, create a recoverable legacy branch before any rewrite, collapse the branch delta back to its base, rebuild it into exactly N intent-based commits, then rebase onto origin/main only when the rewritten branch is not already stacked on it.
Assume local-only history rewriting by default. Do not push, force-push, or delete archive branches unless the user explicitly asks.
Delegate branch diff collection and risk briefing to branch-onboarding-brief before touching history. The onboarding output must be code-grounded: it must include actual changed-file reading and AST-oriented inspection of risky modules, not just git metadata.
Capture and keep:
Do not duplicate the onboarding collector inside this skill.
Before any destructive command, verify repository state once:
git rev-parse --is-inside-work-tree
git branch --show-current
git status --short
git fetch origin main
Require all of the following before rewriting:
HEAD is attached to a named branchorigin/main resolves successfullyN and N is a positive integerIf git status --short is non-empty, stop and report the blocker. Do not auto-stash, reset, or discard local edits.
Capture stable refs once:
original_branch=$(git branch --show-current)
original_head=$(git rev-parse HEAD)
main_tip=$(git rev-parse origin/main)
base_commit=$(git merge-base "$original_head" "$main_tip")
Treat base_commit != main_tip as “not directly based on current main”, which means a rebase is required after regrouping.
Create a local archive branch from the untouched original tip before any reset or rebase.
ts=$(date +%Y%m%d-%H%M%S)
safe_branch=${original_branch//\//-}
archive_branch="legacy/${safe_branch}-${ts}"
git branch "$archive_branch" "$original_head"
Rules:
-1, -2, and so on until uniqueInspect the total branch delta first:
git log --oneline "${base_commit}..${original_head}"
git diff --name-status "${base_commit}...${original_head}"
git diff --stat "${base_commit}...${original_head}"
Before deriving clusters, inspect actual changed code on the branch. Git history alone is insufficient for reliable rechunking, because the target branch should express consolidated semantic changes rather than a cleaned-up copy of the old commit boundaries.
Minimum clustering-grounding contract:
git diff ... --name-statusprobe-deep-searchprobe symbols, probe extract, and probe query on changed Python modules to understand the real function/class boundariesSuggested commands:
probe symbols src/stowage/planner/spp/pipeline.py
probe extract src/stowage/planner/spp/pipeline.py#run_loading_spp_pipeline_result
probe query "class $NAME: $$$" src/stowage/planner/spp --language python
Then derive exactly N clusters using references/commit-clustering.md.
Clustering rules:
Exact-N contract:
N, merge the closest related clusters and state the merge rationaleN, split only along real sub-intents or hunk boundariesAfter the clustering plan is stable, collapse the branch history while keeping the full diff in the working tree:
git reset --soft "$base_commit"
git reset
At this point:
HEAD points at base_commitStage each planned cluster in dependency order and commit immediately.
For file-scoped clusters:
git add path/to/file_a path/to/file_b
git commit -m "<intent-focused message>"
When a single file belongs to multiple clusters, choose the least-lossy replay method first.
For small overlaps, split by hunk:
git add -p path/to/file
For heavy overlaps across multiple original commits, replay the file state commit-by-commit instead of hand-splitting every hunk:
git restore --source <old-commit> --staged --worktree -- path/to/file_a path/to/file_b
git commit -m "<intent-focused message>"
If the later cluster deletes a file that an earlier replay restored, remove it explicitly in the later cluster:
git rm path/to/file
git commit -m "<intent-focused message>"
Use commit-state replay when it is easier to reproduce the original branch intent by restoring exact file states from old commits than by manually curating patches with git add -p.
After each commit:
Before moving on, confirm the remaining diff still matches the unfinished plan:
git status --short
git diff --stat
After the Nth commit, require a clean tree:
git status --short
If changes remain, the regrouping is incomplete.
If base_commit already equals main_tip, skip rebase.
Otherwise, rebase the rewritten stack onto origin/main:
git rebase origin/main
If conflicts appear:
git diff --name-only --diff-filter=U
Resolve conflicts intentionally, then continue with:
git add <resolved-files>
git rebase --continue
If the shell blocks on editor launch, retry with:
GIT_EDITOR=true git rebase --continue
Do not use git rebase --skip or git rebase --abort unless the user explicitly asks or the workflow becomes unrecoverable.
Report the rebuilt stack first:
git log --oneline --decorate -n "$((N + 5))"
Validation rules:
git range-diffSuggested checks:
git diff --exit-code "$archive_branch" HEAD
git range-diff "${base_commit}..${archive_branch}" "origin/main..HEAD"
Interpretation:
git diff --exit-code is only valid as a strict equality check when rebase was skippedgit range-diff is the primary post-rebase proof that the branch intent survived the rewriteInclude in the final handoff:
N and delivered commit countgit status --short before every destructive git command.git add -p only when the same file truly spans multiple intents. If a file appears in multiple candidate clusters, inspect it structurally with probe before choosing between split-by-hunk and commit-state replay.git restore --source <commit> replay over fragile repeated hunk surgery.branch-onboarding-brief: mandatory before any rewrite.main-merge: do not call for this workflow; this skill performs rebase, not merge.code-health: use only when regrouping exposes unusually large or risky non-test churn.references/commit-clustering.md: heuristics for turning one branch diff into exactly N coherent commits.