Pro Git explains git reset
like this:
Recap
The
reset
command overwrites these three trees in a specific order, stopping when you tell it to:
- Move the branch HEAD points to (stop here if
--soft
)- Make the Index look like HEAD (stop here unless
--hard
)- Make the Working Directory look like the Index
The way I understood is that, if I do git reset --hard
, then both my index and my working directory would become EXACTLY like my HEAD. So I went ahead and did this:
# make a git repo
mkdir mygitrepo
cd mygitrepo
git init
# init commit
touch old_file
git commit -a
# stage a file
touch staged
git add staged
# create file that is not staged
touch unstaged
So far my repo looks like this:
HEAD
old_fileindex
old_file + stagedworking dir
old_file + staged + unstaged
Now if I run git reset --hard
then I expect my repo to become:
HEAD
old_fileindex
old_fileworking dir
old_file
But I would get this instead:
HEAD
old_fileindex
old_fileworking dir
old_file + unstaged
I did similar test by explicitly passing target argument, like git reset --hard target
, and I got similar result: staged files are all gone, but unstaged files are still present after git reset --hard
.
Could some one explain if I misunderstood anything about git reset
?