Rescuing Work with the Reflog and Stash
Master Git's safety nets: use the reflog to recover from bad resets and rebases, and use the stash to safely set aside and restore in-progress work during recovery.
Git Rarely Loses Data
It feels like a bad reset or rebase destroys work, but Git almost never truly loses commits. They become unreachable, not deleted, and remain recoverable for weeks.
The reflog is your map back to them.
What the Reflog Records
The reflog logs every move of HEAD and branch tips: commits, checkouts, resets, rebases, merges. It is local and not shared, a private diary of where your refs have been.
git reflog
# a1b2c3d HEAD@{0}: reset: moving to HEAD~3
# 9f8e7d6 HEAD@{1}: commit: add featureAll lessons in this course
- Recovering Lost Commits and Branches
- Debugging with Git Bisect
- Optimizing Git Repository Performance
- Rescuing Work with the Reflog and Stash