Git Reset

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>.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s