git-absorb: git commit --fixup, but automatic
34 points by krig
34 points by krig
jj has appeared and kicked off a new round of discussion around git ergonomics (and git history was recently added to git), but I don't think enough people know about git absorb which I use daily at work. My current workflow is to set up the rough series of commits that I want in a pull request, and then as I develop I git absorb the fixes into the appropriate commits as I go.
I'm kinda hoping absorb can leverage history somehow to speed up the pairing performance. It would be a great outcome.
Oh yes, but for more than performance: I'm always compiling by the time I'm fixing up commits. Patching the source code while compiling it is very UB in terms of build system correctness. I don't know how people can work with that.
I use git-revise for the same reason.
I started using git absorb after some kind soul linked it in another lobste.rs thread some time ago. It's wonderful! I've been maintaining a fairly deep stack of PRs for one of my clients because review times are pretty long, and git absorb makes it feel like a total non-issue. I can always just make changes at the head of my stack, absorb them into the appropriate commit in the history, and then use my git push-stack alias from this blog post to update all of my PRs.
Magit also has integration with it! git absorb has been a useful part of my toolbox.
wait... where?
c a in a magit buffer should be labeled "Absorb". by default it does magit-commit-autofixup which uses git-autofixup but can be configured to use magit-commit-absorb instead which uses git-absorb.
In my config i have:
(with-eval-after-load 'magit-commit
(transient-replace-suffix 'magit-commit 'magit-commit-autofixup
'("x" "Absorb changes" magit-commit-absorb)))
Graphite claims to offer a "stack" aware version https://www.graphite.com/docs/command-reference#gt-absorb
Why would you rewrite history just to address review feedback? That seems confusing.
So the commit that you originally got incorrect, is now correct. If a reviewer comes by and reviews your code afresh commit by commit then they won't have to view something you later changed completely.
This is all dependent on how you structure your unit of change and the commits within that.
This applies to stacked PR/stacked diff workflows followed by many organizations that aren't on GitHub. These workflows focus on atomic, bisectable commits.
another example: write a change, push, get dinged by linter. You wouldn't want that to be a separate commit. You'd want that to have been part of the original change. So you fix it up and git absorb et voilĂ !
I also use this when running the big CI suite and I find an edge case that broke something I hadn't thought about. Fix the edge case, add a test. git absorb will put the fix into a fixup! commit and I can amend that with the test to pop it all into the original commit.
I use this thing 50-100 times a day when I'm really churning.