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

How do you recover a commit after `git reset --hard`?

IntermediateConceptUndoing changes: reset, revert, restore and reflog
Answer

The commit still exists until garbage collected. Find it in the reflog and point a branch to it.

git reflog
git reset --hard HEAD@{1}
# or
git branch recovered 3fa9c21
All Git & GitHub questions Roadmap: Git & GitHub

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