rgit absorb stops on a hunk and leaves files staged, so fold with per-path fixup commits
Symptom#
rgit absorb --toon prints error: hunk at line 431 did not apply (the number changes per attempt) and folds nothing. The next call says error: you have staged changes; commit or unstage them before absorbing. A plain git commit --fixup=<hash> after that creates a fixup that holds many unrelated files.
Cause#
Absorb routes each hunk to the commit that last touched its lines. A hunk whose lines come from several commits cannot be applied, and absorb stops. Each failed attempt leaves the hunks it already applied staged in the index. A later git commit --fixup then commits that staged content too.
Fix#
- Clear the index:
git reset -q(the working tree stays). 2. Map each modified file to the last branch commit that touched it:git log -1 --format='%h %s' $(git merge-base HEAD origin/develop)..HEAD -- <file>. 3. Commit each group with explicit paths:git commit --only --fixup=<hash> -- <paths>.--onlyignores everything else that is staged. 4. Fold them all:GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash <merge-base>. Make a backup ref first:git update-ref refs/backup/pre-fold HEAD(a ref outside refs/heads is not moved by rebase.updateRefs). 5. If a changelog links to commit hashes, remap the stale ones afterwards: read each old subject withgit log -1 --format=%s <old>, find the new hash withgit log --grep=<subject> --fixed-strings -1 --format=%H, rewrite the links, and fold that into the changelog commit.
Evidence#
A branch of 16 commits and 37 modified files: absorb failed twice (hunk at line 431, then hunk at line 729, two different files). After git reset -q and nine git commit --only --fixup=<hash> -- <paths> commits, the autosquash rebase finished without conflicts, and git diff between the tree before and after the rebase was empty. After the rebase 12 changelog commit links were stale and were remapped by subject.
Also found by searching
- error: hunk at line 431 did not apply
- rgit absorb fails: you have staged changes; commit or unstage them before absorbing
- how do I fold many working-tree changes into the right earlier commits when absorb fails
- git commit --fixup swept in files that a failed absorb had staged