Recover from inadvertent skip during rebase

First, make a tarball of your git working folder. This makes it easier to try it several times.

Lets assume the following happened

  • git checkout another-old-branch
  • git rebase master
  • some problems (which you skipped)

at this point you are now still in another-old-branch and your reflog shows you:

6f8348f HEAD@{0}: rebase: <commit message of last commit in another-old-branch>
e547ec0 HEAD@{1}: checkout: moving from another-old-branch to e547ec0d2a558d189464fc57192066b34ec5f28f^0
65cedf8 HEAD@{2}: checkout: moving from master to another-old-branch

Imagine that branchs are like symlinks (or pointers), all we have to do is let the branch ‘another-old-branch’ point back on the old commit-id. the old commit is is still there, and it wasn’t touched by your rebase. kinda: ‘hey git, another-old-branch is e547ec0d2, forget everything else that happened’

In our case here that was e547ec0d2a558d189464fc57192066b34ec5f28f, so what we have to do now is

  • git checkout another-old-branch # if you aren’t already there
  • git reset –hard e547ec0d2a558d189464fc57192066b34ec5f28f

now your branch is back to normal. And you can retry your rebase.

Please note that your reflog is by now a little bit more complicated than aboves example. but it should stil lbe there somewhere…

good luck!

Leave a Comment

techhipbettruvabetnorabahisbahis forumu