3

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?

1
  • Did you try providing it in reverser oder? First !/**/foo/**/bar/**, then /**/foo/** ? I dont know if that will work, but I'd try. Commented May 25, 2014 at 23:10

2 Answers 2

2

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/**
!*/
0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.