Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove a single file from the staging area (undo git add)?

Situation: I have a Git repository with files already in the index. I make changes to several files, open Git and add these files to my staging area with "git add ."

Question: How do I remove one of those files from the staging area but not remove it from the index or undo the changes to the file itself?

like image 264
PHLAK Avatar asked Oct 01 '09 19:10

PHLAK


2 Answers

If I understand the question correctly, you simply want to "undo" the git add that was done for that file.

If you need to remove a single file from the staging area, use

git reset HEAD -- <file>

If you need to remove a whole directory (folder) from the staging area, use

git reset HEAD -- <directoryName>

Your modifications will be kept. When you run git status the file will once again show up as modified but not yet staged.

See the git reset man page for details.

like image 84
Tim Henigan Avatar answered Oct 06 '22 23:10

Tim Henigan


git rm --cached FILE 

,

git rm -r --cached CVS */CVS 
like image 34
user335425 Avatar answered Oct 07 '22 00:10

user335425