Interview Prep/Git & GitHub/Undoing changes: reset, revert, restore and reflog

How do you undo a rebase that went wrong after it finished?

IntermediateConceptUndoing changes: reset, revert, restore and reflog
Answer

Use the reflog: the branch moved at each replayed commit, so find the entry just before rebase (start) and reset to it. ORIG_HEAD also works if nothing else has moved it.

git reflog
git reset --hard HEAD@{N}   # entry before "rebase (start)"
All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing changes: reset, revert, restore and reflog