Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recover last interactive rebase TODO after abort?

Tags:

git

Let's say I'm doing an interactive rebase of a branch containing around 20 commits. In the TODO file, I squash, reword, and reorder commits. All together it's a lot of work to setup this rebase because there is a bunch to do.

Over half way through the rebase, I bork something. I cancel the rebase by doing git rebase --abort. I start the rebase again to do it all over, because I messed up a single commit along the way (maybe I resolved a conflict poorly and didn't realize it until later through the rebase process).

Now I have to edit the TODO all over again. Does Git not remember the last TODO file I configured? Can it not remember the commit messages I reworded?

Perhaps a more simple question is, instead of aborting a whole rebase just to fix a simple mistake, is there perhaps a way to just rewind the interactive rebase back a few steps and restart from that point?

like image 461
void.pointer Avatar asked Jun 14 '14 00:06

void.pointer


1 Answers

For each successful step in the rebase a new commit will be created, and recorded in the reflog. So you could leverage that to essentially start over at the last successful point with a new rebase.

Example:

git rebase --abort # Oops! I notice I messed up during rebase
git reflog         # find the last "good" rebase hash created

git rebase -i --onto <last-good-hash> \
<branchname>~<number of commits that were not replayed>

This is a rather clunky approach but considering a long/difficult rebase, it might be worth it. This essentially recreates the TODO beginning at the point that you aborted.

like image 50
Jeff Ward Avatar answered Nov 15 '22 17:11

Jeff Ward