Ignore file types except for a specific folder (and all subfolders)?

I am trying to customize a .gitignore file so that all files with a specific extension are ignored, unless they appear in a specific folder or in any subfolder of this folder. I tried the following which does not work:

 *.lib !Libraries/ 

The second question I have is negative exceptions that apply only to the previous rule or all the rules that you defined up to this point? -

This almost answers my question, but does not help for subfolders.

+4
source share
2 answers

I think you meant to ignore all *.lib , except when they are inside /Libraries , try this:

 # The root directory .gitignore *.lib !/Libraries/*.lib # The .gitignore under /Libraries directory !*.lib 

.gitignore from top to bottom. Any rule may override previous rules.

+6
source

Try using a double asterisk, ** . Something like this in your .gitignore might work:

 *.lib !/Libraries/**/*.lib 

A double asterisk matches any combination of subdirectories. This answer explains how it works quite well.

As for your second question, @Tuxdude is correct: the rules will override other rules to this point due to how .gitignore .

+4
source

All Articles