Help, I want to throw away my last commit completely
Delete the last commit and its changes, or undo it with a new commit if you have already pushed.
The fix
git reset --hard HEAD~1Deletes the last commit and resets all tracked files. The commit stays findable in
git reflogfor a while; uncommitted changes do not.Discards uncommitted changes
git revert --no-edit HEADAdds a commit that undoes the last one. History stays intact.
git pushShare the undo.
git reset --hard HEAD~1Before
After
Why this works
reset --hard moves the branch back and resets every tracked file to match. The commit is not destroyed straight away: git reflog can still find it for a while, in case you change your mind. Uncommitted edits to tracked files are another story: those are gone for good. Untracked files are left alone. After a push, revert is the safe way: the commit stays in history and a new commit cancels it out.