Vasu Patel logoVasu Patel
← Git Mastery
All chapters in this track
  1. 011. The Mental Model
  2. 022. Essential Setup
  3. 033. Core Daily Workflow
  4. 044. Branching
  5. 055. Merging & Conflict Resolution
  6. 066. Rebasing
  7. 077. Remote Repositories
  8. 088. Stashing
  9. 099. Undoing Things
  10. 1010. Tagging & Versioning
  11. 1111. Cherry-Pick
  12. 1212. Git Bisect & Blame
  13. 1313. Git Hooks
  14. 1414. Submodules
  15. 1515. Team Workflows
  16. 1616. Power Commands & Aliases
  17. 1717. Reflog: The Safety Net
  18. 1818. Practice Tasks
  19. 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.