Tutorial :Recover from inadvertent skip during rebase


I just tried to rebase a very old branch with a minor modification onto my master. There was a problem with merging just one of the three files involved, so I did an unthinking --skip, thinking that it would just skip that file, but as it happened, it seems to have skipped all my changes, and rolled forwards. So now the rebase is finished, and my changes seem to have disappeared.

I've seen the question about undoing rebase, but it's all greek to me, I see the reflog, but I don't know which commit the branch was attached to before the rebase.

In any case, I don't really need to undo the rebase, I just want to be able to recover the changes in the two files. Is there anyway to do this properly (failing this, I'll just have to restore yesterday's backup of my repository and pick the bits out by hand).


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!

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »