git reset --soft vs --mixed vs --hard

All three move your branch back to another commit. --soft keeps the changes staged, --mixed (the default) keeps them in your files but unstaged, and --hard throws them away so your files match that commit exactly.

Step by step

  1. Undo a commit, keep its changes staged:

    $ git reset --soft HEAD~1
  2. Undo a commit, keep its changes unstaged:

    $ git reset HEAD~1
  3. Undo a commit and discard its changes:

    $ git reset --hard HEAD~1
  4. Discard all uncommitted changes:

    $ git reset --hard
BranchStaging areaYour files
--softmoveskeptkept
--mixedmovesresetkept
--hardmovesresetreset

Only reset commits you haven't pushed. For pushed commits, use git revert.

Try it in the interactive sandbox →Practice “Undo the commit” with a real repository and teammates, right in your browser.

Related guides