What is the difference between git reset --soft, --mixed and --hard?
All three move the branch to another commit. --soft keeps your changes staged, --mixed (the default) keeps them but unstaged, and --hard throws them away completely.
Explain it simply
Say you made three commits and want to undo the last one. Reset moves the branch back; the three modes decide what happens to the work from that commit.
--soft leaves the changes staged, ready to commit again, handy for combining commits. --mixed unstages them but leaves the files edited. --hard resets files too, deleting uncommitted work, so use it carefully. Think of three drawers: soft keeps the papers on the desk in the outgoing tray, mixed puts them on the desk, hard puts them in the shredder.
Example
git reset --soft HEAD~1 # undo commit, keep changes staged
git reset HEAD~1 # --mixed: keep changes, unstaged
git reset --hard HEAD~1 # undo commit and delete the changesWhat to say in the interview
"All three move the current branch to the target commit. Soft keeps changes staged, mixed unstages them but keeps the files, and hard resets the working directory too and loses uncommitted changes. I reach for --hard only when I really want to discard work."
Common mistakes
- Running --hard with uncommitted changes you still need.