Video in progress
How do `git reset --soft`, `--mixed` and `--hard` differ?
All three move the branch back to the given commit. --soft leaves the changes in staging, --mixed (the default) leaves them on disk but takes them out of staging, and --hard removes them completely.
📖 Answer
Say you want to rework the last three commits: git reset <mode> HEAD~3.
| Mode | Branch pointer | Staging | Files on disk |
|---|---|---|---|
--soft |
goes back | the changes stay | unchanged |
--mixed |
goes back | cleared | unchanged |
--hard |
goes back | cleared | return to the commit's state |
How it is used in practice:
git reset --soft HEAD~3 # handy for squashing three commits into one
git commit -m "Hisobot eksporti"
git reset HEAD~1 # "open up" the last commit and recommit it in pieces
git reset --hard origin/main # throw away the local experiment and match the server
Think twice before --hard: uncommitted changes do not come back. Committed ones can still be recovered through reflog.
Sign up to mark studied questions and save your progress.