Undo the last commit and throw its changes away
Destructive: deletes work
Short answer
Run git reset --hard HEAD~1. The commit and its changes are gone from your branch and your files (and any uncommitted edits too).
--hard also wipes any uncommitted edits in tracked files, with no undo for those. Run git status first. The commit itself can still be rescued for a while with git reflog (see I reset or deleted commits by mistake). Never use it on commits you've pushed.
The commands, one by one
- 1
git statusLook first: anything listed as modified would be wiped too. Commit or stash it if you want to keep it.
- 2
git reset --hard HEAD~1Moves the branch back one commit and makes your files match that commit exactly. Git prints HEAD is now at… with the commit you're back on.