I'm excluding a folder a and its subfolders, but want to have a specific subfolder b included, where b can be a subfolder somewhere below a, and the exact path to b has not been specified.
My .gitignore
contains these lines:
a/**
!a/**/b
however this does not work. Have tried numerous other permutations of the above, including from other posts on stack overflow, but nothing appears to work.
The previous question on stackoverflow deals with the situation where you can explicitly declare the path to the subdirectory. In this question, the situation I'm addressing is where b
can be any subfolder underneath a
, and not a predetermined path.
Further the earlier solution requires you to "unignore" every parent directory of anything that you want to "unignore". However in this case I'm trying to create a generic rule that allows this subdirectory without bothering about where it is in the directory tree. So the earlier solution does not work/apply in this situation.
If you tell git to ignore a directory, it will completely ignore everything inside that directory. This means git cannot match your exclude because git is simply not looking at it.
The only way to use excludes in a meaningful way is for a single directory, where you ignore everything but some folder like this:
/some/path/*
!/some/path/foo
This will ignore all entries but foo
directly under /some/path
.
But, most of the time it is much clearer to just explicitly ignore things than using excludes.