All fixes

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

  1. git reset --hard HEAD~1

    Deletes the last commit and resets all tracked files. The commit stays findable in git reflog for a while; uncommitted changes do not.

    Discards uncommitted changes
What happens to your historygit reset --hard HEAD~1
BeforeABCHEADmain
AfterABCHEADmain

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.