Cheatsheet Pages / Git Cheatsheet

How to undo the last commit in Git — git reset --soft vs --mixed vs --hard

You committed too early, or to the wrong branch, and want the last commit undone.

git reset --soft HEAD~1    # undo last commit, keep changes staged
git reset --mixed HEAD~1   # undo last commit, unstage, keep edits (default)
git reset --hard HEAD~1   # ⚠️ undo last commit AND delete all changes

Good to know

--soft keeps everything staged, --mixed unstages but keeps edits, --hard deletes everything.

Git Cheatsheet one-page card — 30 daily and rescue commands
The full one-page card — Git Cheatsheet. Get the complete cheatsheet on GitHub