What is the difference between soft, mixed and hard reset in Git?
| Mode | Staging area | Working files |
|---|---|---|
--soft | Keeps the changes staged | Not changed |
--mixed (default) | Cleared, changes unstaged | Not changed |
--hard | Cleared | Changes deleted |
Terminal output
$ git reset –soft HEAD~1
$ git status -s
M f.txt
$ git commit -q -C ORIG_HEAD
$ git reset HEAD~1
Unstaged changes after reset:
M f.txt
$ git status -s
M f.txt
$ git commit -q -a -C ORIG_HEAD
$ git reset –hard HEAD~1
HEAD is now at 2875ee0 First
$ git status -s
$ cat f.txt
one
Look at the M (staged) after soft, M (not staged) after mixed, and the clean status with the line “two” gone after hard. See Git Reset.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |