ShareYourGroupShareYourGroupGit Help

Undo the last commit and throw the changes away

The last commit was wrong and I do not want any of it.

The problem

The last commit was wrong and I do not want any of it.

How the practice repository looked before

$ git status --short --branch
## main
$ git log --oneline -5
7c26407 Add line two
de1ce31 Add notes

The fix

$ git reset --hard HEAD~1
HEAD is now at de1ce31 Add notes

Check the result

$ git status --short
(no output: that is normal)
$ git log --oneline
de1ce31 Add notes
$ git reflog -3
de1ce31 HEAD@{0}: reset: moving to HEAD~1
7c26407 HEAD@{1}: commit: Add line two
de1ce31 HEAD@{2}: commit (initial): Add notes

Why this works

--hard moves the branch back and also resets your files to match, so the work in that commit is no longer in your folder. It is not gone at once: git reflog still lists it for a while (see the page on recovering a lost commit).

If this is not quite your case

If you ran this by mistake, do not panic: the commit is still in the reflog. Run git reflog, find the line before the reset and go back to it with git reset --hard HEAD@{1}. If you only wanted to change the commit, --soft would have kept your work.

Be careful: --hard also discards uncommitted changes to tracked files. Check git status first.

This is an independent guide. It is not connected with the Git project, GitHub, GitLab or any company named here. Every command below was run on 14 November 2026 with the real program (git version 2.56.0.windows.4) in a new empty practice repository; the output shown is what it printed. Facts about options were read in the official Git documentation on 14 November 2026.