Add all files using git add except one directory

Issue

I am trying to add all the files to my git index using

git add -A

However, there is one directory with very large files that is causing this error:

fatal: confused by unstable object source data for 9f8c02a8d2a04d7fffed08b299a0cb8996ab7ecb

Therefore, the adding process is broken! How can I tell git I want to exclude this directory while adding everything else? Available online solutions first add everything and then remove some files. Obviously, I cannot do this because git crashes while adding the files in that specific directory.

Solution

If your Git version is new enough,

git add -- . ':!<path>'

. means all under the current directory, and ':!<path>' means to exclude the path. So it means to add all except path.

The term for . ':!<path>' is pathspec. However, the doc is a bit obscure and lack of abundant examples. I find this post very helpful to understand pathspec.

Answered By – ElpieKay

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published