How do .gitignore exclusion rules actually work?
I have a similar situation, my solution was to use:
/a/**/*
!/a/**/foo
That should work for an arbitrary number of intermediate directories if I read **
correctly.
/a/b/c/* !foo
Seems to work for me (git 1.7.0.4 on Linux). The *
is important as otherwise you're ignoring the directory itself (so git won't look inside) instead of the files within the directory (which allows for the exclusion).
Think of the exclusions as saying "but not this one" rather than "but include this" - "ignore this directory (/a/b/c/
) but not this one (foo
)" doesn't make much sense; "ignore all files in this directory (/a/b/c/*
) but not this one (foo
)" does. To quote the man page:
An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again.
i.e., the file has to have been excluded already to be included again. Hope that sheds some light.