Git exclude directories with a specific name except one

I've seen several questions that are similar to this and also read the gitignore manual , but still can't figure it out.

I want to exclude all named folders lib

(there is one for me "lib/"

), except for one folder (maybe in the future) which is a third party that I cannot change which is under <root>/3rdparty/projectX/lib/

.

I've tried this:

!lib/
lib/*
!projectX/lib/

      

but this also includes other lib folders that are not under root

Can I add this folder as an exception? as?

+3


source to share


1 answer


You have several options.

Full path:

lib/
!3rdparty/projectX/lib/

      

Wildcard:



lib/
!*/projectX/lib/

      

The wildcard matches any level of subdirectories:

lib/
!**/projectX/lib/

      

Your gitignore didn't work because it specifically ignores the directory projectX

in the root directory only.

+6


source







All Articles