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.

I would also advice you to take a deeper look at this well explained article (full of examples) on the role of reset.

Need Your Help

Algorithm to get an approximate depth map from an embossed/relief image

algorithm image-processing image-manipulation

I am attempting to read information from pictures of hard plastic ID cards. As a first step, I've been trying to process the pictures to make the text more computer-readable. The pictures are fai...

WaitForNonStaleResults per DocumentStore

.net nosql ravendb

Is there any way to tell RavenDb to use WaitForNonStaleResults mode for all queries of some DocumentStore or DocumentSession?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.