Reputation: 838
I'm trying to understand git reset command. I have a initial commit_A containing a file file_1.
Now I added file_2 in my working directory which I haven't
staged. If I run git reset --hard
now, file_2 still remains in working directory.
But if I stage file_2 and then run git reset --hard
,file_2 is unstaged and also removed from working directory.
Why is file_2 removed from working directory in second case and not removed in first case ?
Upvotes: 1
Views: 161
Reputation: 13891
In the first case, file_2
is not tracked as you just added it to your working directory without staging or embed it into a commit.
Executing git reset --hard
will then have no impact on these file as it's not tracked by git.
In the second case, you started tracking file_2
(by staging it) which means that running git reset --hard
will then reset your working directory including file_2
, it's then removed from both your staging area and your working directory.
I would also advice you to take a deeper look at this well explained article (full of examples) on the role of reset.
Upvotes: 5