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}
You can check the history of the candidate old head by just doing a git log HEAD@{5}
.
If you've enabled 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, though as I haven't verified this recently. You can do this by adding:
[user]
logallrefupdates=true
This will revert the current branch to the exact same state as the remote repository, removing all the files and directories not present on remote.
git reset --hard origin/{branch}
# Note: Any changes not committed will be lost.
git branch newbranch # Create a new branch, saving the desired commits
git checkout oldbranch # Return to old to reset it
git reset --hard HEAD~3 # Move master back by 3 commits (GONE from master)
git checkout newbranch # Go to the new branch that still has the desired commits