Git exclude directories with specific name except one

Viewed 863

I've seen a few questions that resemble this one and also read the gitignore manual, but still can't figure this one out.

I want to exclude all folders named lib (the rules I have is "lib/") except for a single folder (maybe more in the future) that is a 3rd party folder which I can't change its name, which is under <root>/3rdparty/projectX/lib/.

I've tried this:

!lib/
lib/*
!projectX/lib/

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

Is it possible to add this folder as an exception? how?

1 Answers
Related