hero4hire
Git

Undo a rebase

Get a branch back to where it was before an interactive rebase went wrong.

Find the pre-rebase commit

bash
git reflog

Look for the entry just before the first rebase line — usually HEAD@{n}: rebase (start): checkout <sha> or similar, one or two lines below where the rebase entries begin.

Reset the branch to it

bash
git reset --hard HEAD@{5}

Replace 5 with the offset found in the reflog. This is a hard reset, so make sure nothing since the rebase is worth keeping first.

On this page