Accidentally did git reset –hard and lost commits? Reflog keeps history of all HEAD movements.
View Reflog:
git reflog
# Output:
# abc1234 HEAD@{0}: reset: moving to HEAD~3
# def5678 HEAD@{1}: commit: Important feature ← Lost commit!
# ghi9012 HEAD@{2}: commit: Bug fix
Recover Lost Commit:
# Option 1: Checkout specific commit git checkout def5678 # Option 2: Create branch from it git checkout -b recovered-branch def5678 # Option 3: Reset back to it git reset --hard def5678
Reflog Shows:
– All commits
– All resets
– All checkouts
– All rebases
– Kept for 90 days!
Your safety net against mistakes!
