Git: How to Undo a Commit Without Undoing Your Career
fagnerbrack.com
3 min read
View original
Summary (TL;DR)
The author recounts accidentally running `git reset --hard HEAD~3` on main instead of a feature branch, losing three commits. Recovery steps include using `git reflog` to find lost commits, then `git reset --hard` to restore them. The article also covers `git fsck --lost-found` for when reflog entries expire, warns about `git clean -fd` and `git push --force`, and recommends checking `git status` and `git branch` before destructive commands. The main lesson is to pause and verify context before acting.