Skip to main content

Update logical commits with `git absorb`

I sometimes find myself in a particular situation with git. I have a small series of logical commits in a pull request. I need to make some edits.

I could always make the edits on top of the logical commits and push the new commits, but usually, I’d rather edit the logical commits.

My usual workflow for something like this used to be:

Autosquash

Autosquash is pretty helpful. When you rebase, those fixup and squash commits will be reordered and have the appropriate action based on the commit message.

--autosquash
--no-autosquash
When the commit log message begins with “squash! …​” or “fixup! …​” or “amend! …​”, and there is already a commit in the todo list that matches the same ..., automatically modify the todo list of rebase -i, so that the commit marked for squashing comes right after the commit to be modified, and change the action of the moved commit from pick to squash or fixup or fixup -C respectively. A commit matches the ... if the commit subject matches, or if the ... refers to the commit’s hash. As a fall-back, partial matches of the commit subject work, too. The recommended way to create fixup/amend/squash commits is by using the --fixup, --fixup=amend: or --fixup=reword: and --squash options respectively of git-commit.

git-rebase v2.43.0, 2024-01-09

As helpful as autosquash is, it’s relatively transparent. If you made a regular commit, then did an interactive rebase, reordered that regular commit to be underneath the one you wanted to fixup, and changed the action from “pick” to “fixup”, you end up at the same place. These special commands get you some automatic human-readable information in the temporary commit, and the rebase part reads that commit message to do a bit of text editing for you.

I didn’t terribly mind the workflow (git add -p, git commit --fixup, git add -p …, git rebase -i). I do find git add -p over and over to be tedious and have long wished for a way to do everything git add -p does, but with deleting/undoing changes and sorting things into multiple changesets in one go. I stumbled upon git absorb, though, and have found it even nicer.

git absorb

Enter git absorb, a snazzy git plugin. After you install it:

If you don’t want to review the changes during the interactive rebase, you can git absorb --and-rebase.

Have a suggestion? An important correction? Let me know!

If this was helpful or enjoyable, please share it! To get new posts, subscribe to the newsletter or the RSS/Atom feed. If you have comments, questions, or feedback, please email me.