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.
- License 许可
- Unlicense
- 最近更新
- 2026-11-15
- Stars
- ★ 2
- Forks
- 0
01 前言 Front Matter
- name
- stack-fix
- description
- 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.
- argument-hint
- [--dry-run]
- compatibility
- Requires git-branchless and git-absorb
- disable-model-invocation
- false
02 资源文件 2
- 参考文档references/git-absorb.md33 B
- 参考文档references/git-branchless.md37 B
03 SKILL.md 正文
Fix earlier commits in the stack. Tries git-absorb first (automatic hunk routing), falls back to guided manual amend with conflict resolution when absorb cannot help.
Pre-flight
-
Load references — read
references/git-absorb.mdandreferences/git-branchless.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. -
Snapshot current state for post-fix verification:
git sl BEFORE_SHA=$(git rev-parse HEAD)
Path A: Absorb (automatic routing)
Use this path when you have staged changes that fix lines an earlier commit introduced (typos, bug fixes, adjustments to existing code).
-
Check for staged changes:
git diff --cached --statIf nothing is staged, check for unstaged changes and ask the user what to stage. Suggest
git add -pfor selective staging. -
Fix at HEAD, then name the target for each hunk: the newest commit that introduces either the lines it edits or any name it uses. Absorb sees edited lines, not name dependencies. Line proximity never decides the target. If the target is unknown, stop and ask the user.
Every absorb uses
--base <target-commit>^to exclude older commits. The base only bounds the oldest candidate; absorb walks newest to oldest, so every newer commit remains a candidate. It pins the target only when that target is the newest commit. A broader base (origin/main, the stack root) or no base admits unintended older candidates. Fixes for several commits require separate targeted runs, staging only one target's hunks at a time.git absorb --dry-run --base <target-commit>^ -
Review the dry-run output. Show the user which hunks will be absorbed into which commits. Accept a newer target only when the hunk edits lines introduced by that commit: those lines make it the correct dependency target. A choice at or after every used name's introduction satisfies the name dependencies; an older choice is wrong. If absorb picks a commit older than the named target, rerun with a base that excludes it, or stage that hunk alone and use the explicit fixup below. Hunks that commute with every candidate may remain staged; use the same fixup for those.
-
Confirm with the user that the mapping looks correct. If
$ARGUMENTScontains--dry-run, stop here. -
Absorb and rebase:
git absorb --and-rebase --base <target-commit>^ -- --update-refsThe rebase does not run commit hooks: afterwards run the project's hook or lint runner on the changed files (for example
prek run --files <files>). -
Verify the result with
git slto show the updated stack. -
Check for leftover changes:
git diff --cached --stat git diff --statIf the target's hunks commute and remain staged, fold them into the named target explicitly (resolve its current hash after absorb's rebase). For this fixup or a wrong-target hunk, run the content hooks first; if the repository's commit-msg hook rejects
fixup!subjects (such as this repository's convco hook), pass--no-verifyto the transientgit commit --fixup. Absorb's own commits skip hooks.git commit --fixup=<target-commit> GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash --update-refs <target-commit>^ git diff --cached --statConfirm nothing remains staged. For other changes absorb cannot route, use Structural fixes below. Run the project's hook or lint runner after this rebase too.
-
Post-fix verification (see below).
Structural fixes
For changes absorb cannot route beyond the commuting-hunk fixup above, stop and ask the user. Manual amend, git-revise, restack, and branch-repair recipes can rewrite or move a sibling, stacked, or detached worktree. This skill does not attempt those repairs.
Post-fix Verification
Run after either path to confirm the stack is healthy.
-
Show the updated stack:
git sl -
Verify no unintended changes (the diff should show ONLY the intended fix — unexpected files or regions indicate content lost/duplicated during conflict resolution):
git diff $BEFORE_SHA..HEAD --statFor commit-message-only fixes, stop and ask the user; this skill handles content changes only.
-
Verify every commit still builds on its own after the rebase. Use the project's build or test command across
$STACK:git test run -x '<test-command>' --jobs <N> '<revset>'Use
$STACKfor<revset>here so every commit is checked. Size<N>by memory, not cores, and never pass--jobs 0. If no build or test command is identifiable, report this verification as unknown.$STACKis this worktree's own stack. Plainstack()also holds other worktrees' stacks while localmainis behind its upstream (see Selecting your own stack in the reference):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"Report any regressions introduced by the fix.
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-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.
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.
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.