一键导入
stack-restack
Restructure a range of commits into a clean, atomic stack ordered by concern
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Restructure a range of commits into a clean, atomic stack ordered by concern
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Fetch and distill a repo's wiki, docs, and issues into a focused reference doc
Absorb staged changes into the correct commits in the current stack
Break a large commit into a reviewable stack of small atomic commits
Sync stack with main, run tests, and submit all branches to remote
Run tests or formatters across all commits in a stack
| name | stack-restack |
| description | Restructure a range of commits into a clean, atomic stack ordered by concern |
| argument-hint | <range> (e.g. main..HEAD, branch-name, hash1..hash2) |
Restructure a range of existing commits into a clean stack of atomic commits
grouped by concern. The input is a commit range — anything git diff and
git log understand (branch name, main..HEAD, hash1..hash2, etc.).
Check branchless init:
if [ ! -d ".git/branchless" ]; then git branchless init; fi
Parse the range from $ARGUMENTS. Common forms:
main..HEAD or main.. — everything since main<branch> — the branch tip vs its merge-base with main<hash1>..<hash2> — explicit range<hash>..HEAD — from a specific commit to currentResolve to a <base> and <tip>:
# For range syntax (base..tip):
BASE=<resolved base>
TIP=<resolved tip>
# For a branch name, find the merge-base:
BASE=$(git merge-base main <branch>)
TIP=<branch>
Understand the current state. Run all of these:
git sl
git log --oneline $BASE..$TIP
git diff --stat $BASE..$TIP
git diff $BASE..$TIP
Read the full diff carefully. Count the total lines changed.
Analyze and classify every change into logical groups. Standard ordering:
Documentation goes WITH the feature commit it documents, not as a separate commit at the end. Each commit should include the docs for what it introduces. Dependencies (imports, config files) arrive in the commit that first uses them — never frontloaded. Generated files should show incremental additions even if the tool regenerates them wholesale.
For each group, note:
If a file has changes spanning multiple groups, it will need git add -p
to split hunks across commits.
Present the plan to the user. Format as a numbered list:
Proposed stack (N commits, M total lines):
1. refactor(scope): description — files X, Y (~80 lines)
2. feat(scope): add types — files A, B (~120 lines)
3. feat(scope): core logic — files C, D, E (~150 lines)
...
Wait for user approval. Adjust if they have feedback on grouping or ordering.
Check for uncommitted work before starting:
git status --short
If there are uncommitted changes, warn the user and ask whether to stash or commit them first.
Flatten the range into the working tree:
git reset --soft $BASE
git restore --staged .
This uncommits everything in the range but keeps all changes in the working tree. Verify:
git diff --stat # should match step 3's total diff
Commit each group in plan order:
# For file-level grouping:
git add <file1> <file2>
git commit -m "type(scope): description"
# For hunk-level splitting within a file:
git add -p <file>
git commit -m "type(scope): description"
After each commit, verify nothing was missed or double-counted:
git diff --stat # remaining uncommitted changes
Each commit must:
Verify the result:
git sl
Show the user the new stack.
Confirm the total diff is identical:
git diff $BASE..HEAD --stat # should match step 3
Run tests if a test command is identifiable:
git test run -x '<test-command>' 'stack()'
Report any commits that break the build.
git diff --stat matches
the original range diff. If anything is missing, stop and investigate.git add <files> over git add -p for speed.