Acorn
Acorn

Reputation: 50517

How do I remove a directory subtree from the staging area?

I made a new repository, and ran git add -A. I then noticed that there was a folder containing about 100 files that shouldn't have been included, so I added it to .gitignore.

How do I now clear the staging area so that I can add all my files again taking into account the updated .gitignore?

Upvotes: 93

Views: 63384

Answers (4)

Vettis
Vettis

Reputation: 903

With a fairly modern git version you can now do:

git reset foldername/*

I found earliest documentation for this feature from version 2.12.5 onwards, but it might work on older version of git too.

Upvotes: 1

Busilinks
Busilinks

Reputation: 87

Make sure you remember to put the s in --global core.excludesfile .gitignore.txt

excludesfile vs excludefile

Maybe this will save someone else the hour I lost...

Upvotes: 4

Greg Bacon
Greg Bacon

Reputation: 139531

In #git, you said you unintentionally added a directory that should have been ignored, so run

git rm --cached -r directory-name

to recursively remove the tree rooted at directory-name from the index.

Don't forget to update .gitignore!

Upvotes: 191

Matthew Flaschen
Matthew Flaschen

Reputation: 284836

You can just use the command:

git reset

Upvotes: 30

Related Questions