Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git exclude directories with specific name except one

Tags:

git

gitignore

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?

like image 890
ZivS Avatar asked Mar 08 '23 14:03

ZivS


1 Answers

You have a few options.

Full path:

lib/
!3rdparty/projectX/lib/

Wildcard match:

lib/
!*/projectX/lib/

Wildcard match with any level of subdirectories:

lib/
!**/projectX/lib/

Your gitignore was not working because it specifically ignores the projectX directory only in the root.

like image 118
Tom Avatar answered Mar 11 '23 02:03

Tom