Modes and behavior
Show the three reset modes
git reset --soft HEAD~1
Example:
git reset --mixed HEAD~1
Discard staged and working tree changes
git reset --hard HEAD~1
Example:
git reset --hard origin/main
Target specific files
Unstage one file
git reset HEAD src/app.js
Example:
git reset HEAD .
Reset one file to latest commit
git checkout -- src/app.js
Example:
git restore src/app.js
Safer recovery workflow
Preview commit before reset
git show HEAD~2
Example:
git log --oneline -5
Recover with reflog if needed
git reflog
Example:
git reset --hard HEAD@{1}
Common mistakes / Pitfalls
- Running --hard on the wrong branch deletes uncommitted work.
- Using reset after push rewrites shared history and breaks teammates.
- For one file, prefer git restore or checkout instead of full branch reset.
Last updated: February 2026