Git ignore exception does not work multiple subdirectories below the ignored directory

I am having a problem where the exception syntax for gitignore (! FileName.txt) does not work, when the file consists of several subdirectories under an ignored directory.

For example:

web/[Ee]xample.[Ww]eb/[Ss]itecore/* !web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/[Ss]tandard/[Cc]ustom/32x32* 

does not include files in the 32x32 folder.
I have to manually add them via the command line as follows:

 git add -f -r web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/[Ss]tandard/[Cc]ustom/32x32 

Is there a way to use the exception operator in this situation?

+1
git gitignore
source share
1 answer

Re-including a file that "is several subdirectories below the ignored directory" (as you try) does not work because "it is not possible to re-include the file if the parent directory of this file is excluded" [ source ].

As an ugly but working solution, re-include all the parent directories along the path before re-including the file you want, saving the files in these parent directories and excluding them again.

For your example, this would look like this:

 web/[Ee]xample.[Ww]eb/[Ss]itecore/* !web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/ web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/** !web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/ web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/** !web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/[Ss]tandard/ web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/[Ss]tandard/** !web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/[Ss]tandard/[Cc]ustom/ web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/[Ss]tandard/[Cc]ustom/** !web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/[Ss]tandard/[Cc]ustom/32x32* 

Source: my answer is here .

Alternatively , you can use .gitignore files instead, which are placed in the file directory for re-inclusion [ here ]. Depending on the taste, this may be a more beautiful solution.

+1
source share

All Articles