How do I easily undo a git rebase? A lengthy manual method is:
checkout the commit parent to both of the branches
create and checkout a temporary branch
cherry-pick all commits by hand
reset the faulty rebased branch to point to the temporary branch
In my current situation, this works 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 two of my own branches).
Clarification: I am talking about a rebase during which multiple commits were replayed, not only one.
In the reflog… git ref log, the easiest way would be to locate the branch\’s head commit as it was before the rebase began.\n\nIn the ref log: git reset –hard HEAD@2 — and to reset the current branch to it (with the usual caveats about being absolutely sure before resetting with the—hard option).\n\nIn Windows, you may have to quote the reference: git reset –hard \”HEAD@2\”.\n\nFor example, if you\’ve not disabled per branch reflogs (Windows: git log HEAD@2) as a rebase detaches the branch head, you can check the history of the candidate old head by simply logging the corresponding branch branch, but I double-checked this behavior, even though I haven\’t verified this recently. All ref logs are activated for non-bare repositories: [core] logAllRefUpdates = true.