All chapters in this track
- 011. The Mental Model
- 022. Essential Setup
- 033. Core Daily Workflow
- 044. Branching
- 055. Merging & Conflict Resolution
- 066. Rebasing
- 077. Remote Repositories
- 088. Stashing
- 099. Undoing Things
- 1010. Tagging & Versioning
- 1111. Cherry-Pick
- 1212. Git Bisect & Blame
- 1313. Git Hooks
- 1414. Submodules
- 1515. Team Workflows
- 1616. Power Commands & Aliases
- 1717. Reflog: The Safety Net
- 1818. Practice Tasks
- 19Quick Reference Cheatsheet
Chapter 17 of 19
17. Reflog: The Safety Net
git reflog records every place HEAD has pointed — even after resets, rebases, amends, and deleted branches. It's your undo button for Git itself.
git reflog # full history of HEAD movements
git reflog show feature/old # history for a specific branch
# Output example:
# a1b2c3 HEAD@{0}: reset: moving to HEAD~1
# d4e5f6 HEAD@{1}: commit: feat: add user auth
# g7h8i9 HEAD@{2}: checkout: moving from main to feature/login
# Recover a "lost" commit after git reset --hard
git reset --hard d4e5f6 # go back to that commit
# Recover a deleted branch
git branch recovered-branch d4e5f6
Reflog expires (default: 90 days). Commits not referenced by any branch or tag become eligible for garbage collection after that.
Rule of thumb: Before any destructive operation (reset --hard, rebase, branch -D), note down the current HEAD hash with git log --oneline -1. You can always recover.