在Git中忽略忽略目录的子目录

假设我忽略了一个目录,但是我想要在其中指定特定的子目录。 所以我有这样的设置:

/uploads/ /uploads/rubbish/ /uploads/rubbish/stuff/KEEP_ME/ /uploads/foo/ /uploads/foo/bar/lose/ 

我想忽略KEEP_ME目录下的所有内容。 我希望忽略看起来像这样:

 /uploads/* !/uploads/rubbish/stuff/KEEP_ME/ 

但是这不起作用,在同一主题上也不是几个排列组合。

一个工作是

 /uploads/**/**/**/ !/uploads/rubbish/stuff/KEEP_ME/ 

但是这有点限制和冗长?

 #ignore everything within /uploads/ /uploads/* #include everything within /uploads/rubbish/stuff/keep !/uploads/rubbish/stuff/keep/ !/uploads/rubbish/stuff/keep/* 

为我工作。 不要问为什么。

要包含子目录/uploads/rubbish/stuff/keep/添加第三行:

 !/uploads/rubbish/stuff/keep/**/* 

即使你添加了一些.gitignore ,你也可以强制 git将它添加到索引中

 git add --force uploads/rubbish/stuff/KEEP_ME/ 

然而,“KEEP_ME”似乎是一个目录,git通常不会像空文件夹,所以你应该添加一个“占位符”的持有者文件,而不是文件夹是空的

 git add --force uploads/rubbish/stuff/KEEP_ME/.keep_me 

试图找出如何排除具有通用排除的所有文件夹时包含特定的文件夹

 **/build 

如果将/*添加到generics排除的末尾,则继续排除所有构build文件**/build/*

然后添加另一行来纠正你想包含的path

 !**/folder/build/* 

留给我们一个读取的gitignore

 **/build/* !**/folder/build/*