Why is it that git allows me to reset a file? I thought I understood reset
, in the sense that it was moving the HEAD ... clearly I was wrong.
So, git reset sha file
seems to do the same as git checkout sha file
, with the exception that I see file
in the index and in the working directory.
It doesn't make sense to me. Can someone please explain the difference?
Reverts changes to the file.
Removes the file from the staging area, but keeps the changes.
tl;dr
git reset COMMIT FILE
changes only index,git checkout COMMIT FILE
will change both index and working tree.git reset
has very important flags of--soft
,--hard
and--mixed
( and--keep
and--merge
)http://git-scm.com/docs/git-reset
--mixed
is the default and when you dogit reset sha file
you are doingmixed
reset whereby:Like it says above, the reset in this case would not touch your working tree at all and only the version in the index is reset to the one in the sha.
git checkout
on the other hand:So when you do
git checkout
you will lose the changes in the file and it will be replaced with whatever was there in the version of file in sha, whereas when you do the mixed reset, only your index will be reset and your working directory will still have the changes which you can later stage again as needed.