git helper for “recursive rebase”

Very often I’m in the middle of an interactive rebase and while editing a commit I remember I should have changed a commit that I initially didn’t mark on the rebase todo. If you tried to git-rebase again you would notice it’s not possible due to git’s bookkeeping of the current rebase.

In the past what I usually did was to either 1) Continue the rebase and then rebase again to fix the previous commit or 2) Create a fixup commit with git commit --fixup and then rebase again with --auto-squash.

Now I have a helper that I’m calling “recursive rebase”. Under the hood it’s not actually a recursive rebase, but just a way to edit the git-rebase’s todo file so you can rewind it. See it here: git-recursive-rebase. So let’s assume our git log looks like below:

aa7a42b (HEAD -> tip) cast-terminal: wrap asciinema and asciinema-player
0c75f7a Add recursive-rebase for poor souls depending heavily on git-rebase-i
6e70b2c mkosi-resize: rework and fix partition table recreation
60658c8 custom-kernel-install: also support installkernel
615eb02 custom-kernel-gen: also copy System.map
e683b4c git-rebase-compile: log commits being tested
f60f71c Allow removal of symlinks to fail
67c76ee (master) Fix missing char in root partition uuid

I start the interactive rebase on 60658c8 with git rebase -i 60658c8^ and mark to edit that commit.

e 60658c8 custom-kernel-install: also support installkernel
pick 6e70b2c mkosi-resize: rework and fix partition table recreation
pick 0c75f7a Add recursive-rebase for poor souls depending heavily on git-rebase-i
pick aa7a42b cast-terminal: wrap asciinema and asciinema-player

While editing I realize I also want to fixup 2 commits before that. I can do that by using git recursive-rebase HEAD~2 (I actually usually give the commit id by looking at git-log/tig. The new todo file looks like below:

$ git recursive-rebase HEAD~2
...
HEAD is now at e683b4c git-rebase-compile: log commits being tested

$ git rebase --edit-todo
pick 615eb02 custom-kernel-gen: also copy System.map
pick 60658c8 custom-kernel-install: also support installkernel
exec echo "recursive-rebase previously stopped here"
break
pick 6e70b2c mkosi-resize: rework and fix partition table recreation
pick 0c75f7a Add recursive-rebase for poor souls depending heavily on git-rebase-i
pick aa7a42b cast-terminal: wrap asciinema and asciinema-player

Just to help people keep the context on where they are in the rebase we add a line saying that it was previously there and stop the rebase. The command break was recently added to git (v2.20), but changing that to x false should make it work on previous versions as well. Bellow a asciinema recording of my terminal session:

blogroll

social