I always forget about what does git reset do exactly after not using it for a while. So I decided to write it down with diagrams. Below is the usage of git reset with different arguments:
git reset <commit>
- update HEAD+master to point to <commit> (if HEAD is attached to master)
- update index to match <commit>
- working directory(WD) untouched
git reset –soft <commit>
git reset –hard <commit>
git reset — <filename> or git reset HEAD — filename
- unstage the file name <filename>, in other words, if it is a tracked file, it will revert index’s <filename> to HEAD’s <filename>; if it is not a tracked file, it will simply unstage it.
git reset <commit> — <filename>
- work the same as the above git reset — <filename>, but instead of updating with HEAD’s <filename>, it updates with <commit>‘s <filename>.