What does git reset do?

Posted in Articles

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

git reset kind of rolls thing back.   How exactly it rolls things back depends on which of these three you do …

git reset --soft
git reset
git reset --hard

Don’t do the last command, unless you know what you are doing.  It can roll back and wipe out changes in your working directory.

Actually, there is also these commands …

git reset --mixed
git reset --merge

You might want to take a look at the git manual.  But it may be difficult to understand because it says things like …

“In the first and second form, copy entries from <tree-ish> to the index. In the third form, set the current branch head (HEAD) to <commit>, optionally modifying index and working tree to match. The <tree-ish>/<commit> defaults to HEAD in all forms.”

So you might want to instead read the chapter on git about “undoing things” to get the basics.

Others have tried to demystify git reset with some pictures, and others tried with some tables.

But the basic usage “git reset HEAD <filename>” will just reset the file that is on stage with the version that was last committed (without affecting the working copy).  In other words, it would kick the file out of stage.  It will un-stage the file, if you accidentally staged it.