Git Rebase: Stepping Forward and Backward

Stepping Forward

You are in the middle of an interactive rebase in git and you want to go forward *one* commit:

git rebase --edit-todo

Then change the first line of the file to edit instead of pick then save and close the rebase-todo file. Finally run:

git rebase --continue

Stepping Backward

Now imagine that you want to go back one commit, while in the middle of a rebase.

Use

git rev-parse HEAD

or

git show

or

git log --oneline

to get the commit hash of HEAD. Then do

git rebase --edit-todo

and insert a new line at the top to contain:

pick <hashOfCurrentHead>

save and close the file and then do:

git reset --hard HEAD^

to rewind one commit.

You are now back one commit but still in the middle of an interactive rebase.

These could easily be packaged up into git rebase step and git rebase retreat, or something similar, but I haven't gotten around to doing so since it only takes a matter of seconds to do anyway.