git reset --soft vs --mixed vs --hard — the difference

# --soft   → undo commit, keep changes STAGED
git reset --soft HEAD~1

# --mixed  → undo commit, keep changes UNSTAGED  (default)
git reset HEAD~1

# --hard   → undo commit, DISCARD all changes  (destructive)
git reset --hard HEAD~1

All three move HEAD backward — they differ only in what happens to your working directory and staging area.

--soft: safest — keeps everything staged

The commit is removed, but all changes from that commit are left in the staging area, ready to recommit.

git reset --soft HEAD~1
git status          # changes show as "Changes to be committed"
git commit -m "Better message"

--mixed (default): unstages but keeps files

The commit is removed and changes are unstaged, but your actual files are not touched.

git reset HEAD~1
git status          # changes show as "Changes not staged for commit"

--hard: discards everything (use with care)

Cannot be undone easily. All changes from the commit and any unstaged edits are permanently deleted.

git reset --hard HEAD~1
# If you regret this, try:
git reflog          # find the lost commit hash
git checkout -b recovery abc1234