简体   繁体   中英

gitignore: Ignoring a folder (anywhere) except for a subfolder (anywhere)

I want to exclude everything in a folder named foo , except for stuff inside a folder named bar .

foo can appear anywhere in the directory structure more than once.

bar can appear anywhere in the directory structure under foo .

I tried

/**/foo/**
!/**/foo/**/bar/**

but it didn't work. It still ignores all the foo . It refuses to allow bar .

How do I solve this?

From the gitignore documentation :

[A line starting with] An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded.

It seems like this isn't possible.

When you ignore a directory, you tell git to not even look there.

**/foo/**

ignores everything in foo/ , including all the directories. git will never even see a bar directory nested farther down because the above told it to not examine anything in foo

**/foo/**
!**/foo/**/
!**/foo/**/bar/**

will do it, because you overrode the ~don't look~ instruction with ~but do look in all the directories~.

When this alternative makes sense to you, you understand everything :

**/foo/**
!**/foo/**/bar/**
!*/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM