Quick post that’s been rattling around in my head for a while; I just want to get this down, then maybe flesh it out a bit more later.

fixup is a git operation I frequently use that may not be as well known as the common commit, push, pull, etc.

It’s something you need to be a bit careful about, as it “changes history”, and anyone that has your changes before you do the fixup may have some problems with differing commit histories.

I generally use it only for simple additions/updates to a recent commit, like removing some extra logging, or correcting a spelling error.

If you’ve just made a commit, and find there’s something incomplete about it, but the changes aren’t really enough to justify a completely new commit, first find the SHA of the commit you want to fix.

Stage the changes you want to add to the commit, then run the command:

git fixup <SHA to fix>

At this point, the fixup is a new commit at the HEAD of your current branch.

Now find the SHA of the commit before the commit you want to fix, and run the command:

git rebase -i --autosquash <SHA before commit being fixed>

Note that the branch can’t have any other pending changes at this point, so I usually stash things for a bit.

The rebase brings up an editor listing commits after the specified commit, and you can do the usual reword or other things here; I usually don’t, just to keep things simple.

Save and quit the editor, then take a look at your commit history. You’ll find the fixup commit is gone, and the SHAs of the commits after the commit to be fixed have changed. If you haven’t pushed the branch to a remote, just continue your work. If you have pushed the branch anywhere, you’ll need to remember to force push with -f, as well as notify anyone who may have pulled this branch into their own working environment.