ravi
ravi

Reputation: 838

What will happen to uncommited and unstaged files after git reset --hard?

I'm trying to understand git reset command. I have a initial commit_A containing a file file_1.

Why is file_2 removed from working directory in second case and not removed in first case ?

Upvotes: 1

Views: 161

Answers (1)

Ahmed Siouani
Ahmed Siouani

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

Related Questions