Pavel Nasovich's Blog

The Moderately Enthusiastic Programmer

Today I Learned: Undoing a git rebase

Posted at — Jun 20, 2019

The easiest way would be to find the head commit of the branch as it was immediately before the rebase started in the reflog…

git reflog

and to reset the current branch to it (with the usual caveats about being absolutely sure before reseting with the --hard option).

Suppose the old commit was HEAD@{5} in the ref log:

git reset --hard HEAD@{5}

In Windows, you may need to quote the reference:

git reset --hard "HEAD@{5}"

You can check the history of the candidate old head by just doing a git log HEAD@{5} (Windows: git log "HEAD@{5}").

Copied from CB Bailey answer from https://stackoverflow.com/a/135614

comments powered by Disqus