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@{2}
in the ref log:
git reset --hard HEAD@{2}
In Windows, you may need to quote the reference:
git reset --hard "HEAD@{2}"
You can check the history of the candidate old head by just doing a git log HEAD@{2}
(Windows: git log "HEAD@{2}"
).
If you've not disabled per branch reflogs you should be able to simply do git reflog branchname@{1}
as a rebase detaches the branch head before reattaching to the final head. I would double-check this behavior, though, as I haven't verified it recently.
Per default, all reflogs are activated for non-bare repositories:
[core]
logAllRefUpdates = true
Actually, to make this easier Git keeps a reference named ORIG_HEAD
that points where you were before the rebase. So, it's as easy as:
git reset --hard ORIG_HEAD
Best Answer
After a
git pull
operation,ORIG_HEAD
should point to the previous value ofHEAD
. You should be able to:And be back where you started before the
pull
operation. You can run:To see exactly where
ORIG_HEAD
is pointing prior to running thereset
command.An alternative solution would be to create a new branch based on
ORIG_HEAD
:Verify that things look the way you expect, then delete the old branch and rename
new branch
.Also see this question for a discussion of
HEAD
andORIG_HEAD
and alternate syntaxes for referring to the same thing.