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.
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 ?
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.