Undoing a git rebase - git undo rebase
Does anybody know how to undo git rebase?
The only way that comes to mind is to go at it manually:
git checkout the commit parent to both of the branches
then create a temp branch from there
cherry-pick all commits by hand
replace the branch in which I rebased by the manually-created branch
In my current situation, this is gonna work because I can easily spot commits from both branches (one was my stuff, the other was my colleague's stuff).
However, my approach strikes me as suboptimal and error-prone (let's say I had just rebased with 2 of my own branches) then, how to undo git rebase?
Any ideas?
Clarification: I'm talking about a rebase during which a bunch of commits was replayed. Not only one.
The easiest way to undo git rebase is, find the head commit of a branch is using the following commands.
git reflog
and to reset the current branch to it with -- hard option, if suppose old commit was HEAD@{1} in reflog then follow the commands
git reset --hard HEAD@{1}
If you are using windows system then you need to quote it “HEAD@{1}”.
History of the old commit can find in
git log HEAD@{1}
If you've not disabled per branch reflogs
git reflog branchname@{1}
As rebase detaches the branch head before reattaching to the final head.