Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.4k points)

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?

1 Answer

0 votes
by (27.5k points)

You want to 'undo' the git add that was done for a particular file.

Case 1: To remove a single file from the staging area use the following command:

git reset HEAD -- <file>

Case 2: To remove a whole directory (folder) from the staging area use the following command:

git reset HEAD -- <directoryName>

Note that Your modifications will be kept. Also, when you run git status the file will once again show up as modified but not yet staged.

Browse Categories

...