Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to discard staged changes in git without effecting unstaged changes [duplicate]

Tags:

git

In order to include some untracked files in my commit I followed this post and accidently added a lot of unwanted stuff. Now I have this situation in my repo.

2016-02-02 16:51 Unknown            o Staged changes <--- untracked files
2016-02-02 16:51 Unknown            o Unstaged changes <-- want to preserve
2016-01-04 17:01 XXXXX YYYYY        I [wool_task_conversion] [master] [origin/HEAD] [origin/master] First commit

I now want to bring back the untracked files in thier original position i.e. the unstaged area as before preserving the changes in unstaged area for tracked files.

like image 932
Black_Zero Avatar asked Oct 19 '22 16:10

Black_Zero


1 Answers

If you look at the output of git status it actually answers this question:

Davids-Mac-Pro:DAD dhoelzer$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   t

So, simply executing git reset HEAD <file> will do what you are asking.

If you want to remove all staged changes while retaining the changes, the following should be correct:

 git reset HEAD -- .

This should be run from the root of your project.

like image 170
David Hoelzer Avatar answered Oct 21 '22 07:10

David Hoelzer