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
Undo a commit, keep its changes staged:
$ git reset --soft HEAD~1Undo a commit, keep its changes unstaged:
$ git reset HEAD~1Undo a commit and discard its changes:
$ git reset --hard HEAD~1Discard all uncommitted changes:
$ git reset --hard
| Branch | Staging area | Your files | |
|---|---|---|---|
--soft | moves | kept | kept |
--mixed | moves | reset | kept |
--hard | moves | reset | reset |
Only reset commits you haven't pushed. For pushed commits, use git revert.