stack-split
Use when you need to break up, split, or decompose a large commit into smaller atomic commits. Use INSTEAD of manual git rebase -i + edit or git reset HEAD^. Prevents: non-working intermediate commits, wrong split ordering, missed downstream restack.
- License 许可
- Unlicense
- 最近更新
- 2026-11-15
- Stars
- ★ 2
- Forks
- 0
01 前言 Front Matter
- name
- stack-split
- description
- Use when you need to break up, split, or decompose a large commit into smaller atomic commits. Use INSTEAD of manual git rebase -i + edit or git reset HEAD^. Prevents: non-working intermediate commits, wrong split ordering, missed downstream restack.
- argument-hint
- [commit]
- compatibility
- Requires git-branchless
- disable-model-invocation
- false
02 资源文件 2
- 参考文档references/git-branchless.md37 B
- 参考文档references/philosophy.md33 B
03 SKILL.md 正文
Split a large commit into multiple smaller, atomic commits. Target commit defaults to HEAD if not specified.
Pre-flight
-
Load references — read
references/git-branchless.mdandreferences/philosophy.md(relative to this skill's directory) before proceeding. -
Confirm repository initialization. A devenv project with
git.branchless.enablerunsgit branchless initon every shell entry. Anywhere else, check and stop if it is missing:git config --get branchless.core.mainBranch >/dev/null || echo "not initialized: ask the user to run git branchless init"Do not run
git branchless inityourself: it rewrites the repository's shared configuration and hooks for every worktree. -
Check for stale rebase state:
ls -d "$(git rev-parse --git-path rebase-merge)" \ "$(git rev-parse --git-path rebase-apply)" 2>/dev/nullIf either exists, run
git rebase --abortbefore proceeding. In a linked worktree.gitis a file, so ask Git for the paths. -
Select this worktree's own stack as
$STACK, and use it wherever this skill tests the stack:main_branch="$(git config branchless.core.mainBranch || echo main)" remote="$(git config "branch.${main_branch}.remote" || echo origin)" base="$(git rev-parse --abbrev-ref "${main_branch}@{upstream}" 2>/dev/null \ || echo "${remote}/${main_branch}")" git rev-parse --verify -q "${base}^{commit}" >/dev/null || base="$main_branch" STACK="descendants(roots((stack() & ::HEAD) - ::$base)) - ::$base"$baseis main's upstream ref (the last fetched one), or localmainwhen there is none. Plainstack()is not your stack while localmainis behind its upstream, the normal state when worktrees branch fromorigin/main: it also holds the upstream commits and every stack another worktree branched from them. See Selecting your own stack inreferences/git-branchless.md.
Steps
-
Identify the target commit. If
$ARGUMENTSis provided, use it. Otherwise default to HEAD. -
Analyze the commit to understand what it contains:
git show --stat <commit> git show <commit>Read the full diff. Identify logical groups following the ordering in
references/philosophy.md:- Refactoring / cleanup (should be first)
- Type definitions / interfaces / schemas
- Core logic changes
- Edge cases / error handling
- Tests
Documentation belongs with the feature it documents, not as a separate split. Dependencies and config files go in the commit that first uses them.
-
Propose a split plan to the user. For each proposed commit:
- One-sentence description
- Which files/hunks belong to it
- Why it's a separate concern
Wait for user approval before proceeding.
-
Perform the split using interactive rebase:
git rebase -i --update-refs <commit>^--update-refsmakes Git move every branch inside the rebased range onto the rewritten commits, including the ones between the split commit and HEAD.Mark the target commit as
edit, then:git reset HEAD^This unwinds the commit but keeps all changes in the working tree.
-
Stage and commit each group in the agreed order:
git add -p # or git add <specific-files> git commit -m "descriptive message for this group"Repeat for each logical group. Each commit must:
- Be describable in one sentence
- Leave the codebase in a working state
- Target 50-200 lines
-
Complete the rebase:
git rebase --continue -
No restack is needed.
--update-refsalready moved the downstream branches. branchless may still warn that the rebase abandoned them: it prints that just before Git moves them. Step 8'sgit slshows whether any branch is left on arewritten ascommit. If one is, stop and ask the user. Do not repair it with a restack or subtree move; the abandoned line may belong to a stacked or detached worktree. -
Verify the result:
git slShow the user the new stack. If a test command is available, run tests over the new commits:
git test run -x '<test-command>' --jobs <N> '<revset>'Pick
<revset>per Choosing the test revset inreferences/git-branchless.md, readingstack()there as$STACK. Splitting is one of the cases that argues for$STACKeven inside a single PR — you have just created commits that never existed before — but say so rather than widening silently, and size<N>by memory, not cores.
Alternative: Full Stack Restructure
If the user wants to restructure multiple commits (not just split one), use
/stack-plan instead.
Tips
- Do not substitute git-revise for the guarded rebase above. Its branch repair would require moving repository-global refs after the rewrite.
- Format changes should ALWAYS be a separate commit (they dominate diffs and hide functional changes)
- If a file has both refactoring and new logic, use
git add -pto split hunks within the file - Prefer too many small commits over too few large ones — they can always be squashed later
- Each commit message should explain WHY, not just WHAT
04 同仓库更多 Skills
stack-test
Use when you need to run tests or formatters across commits in a stack. Use INSTEAD of manual git test run or looping git checkout + test. Prevents: testing every commit when only the tip has to pass, unbounded parallel jobs exhausting memory, cache misunderstandings.
stack-summary
Use when you need to audit, analyze, or review stack quality before restructuring. Produces a structured summary with per-commit classification, philosophy audit, and violation flags. Output feeds directly into /stack-plan restructure mode. Use INSTEAD of manual git log inspection.
stack-submit
Use when you need to push, submit, or create pull requests for a commit stack. Rebases only the current stack onto upstream main, validates, and pushes INSTEAD of manual git sync + git submit + PR/MR creation. Handles branch creation, stacked PR/MR creation with correct base branches.
stack-plan
Use when you need to plan commits, restructure a stack, or commit uncommitted work as organized atomic commits. Builds a stack from a description, uncommitted work, or existing commits INSTEAD of dumping everything into one monolithic commit with git add -A && git commit, or manual git rebase -i, git reset --soft, or ad-hoc git move sequences. Prevents: wrong commit ordering, forward references, git move -F panics, untested intermediates.
stack-fix
Use when you need to fix, correct, or update content in an earlier commit — line-level edits, content moves, or structural changes. Absorbs staged changes into correct stack commits INSTEAD of running git absorb or git commit --fixup via Bash, or hand-running git prev + edit + git amend + git restack --merge. Prevents: missed dry-run preview, leftover staged changes going unnoticed, forgetting to restack. Falls back to guided manual amend when absorb cannot route hunks.
peer-communication
How to write replies a person reads: answer first, plain words, easy to scan. Load before your first reply in an interactive session.