git gitignore 目录模式忽略具有相同后缀的文件夹,但我想包括它

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/985890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 06:35:29  来源:igfitidea点击:

gitignore directory pattern ignores folder with same suffix, but I want to include it

gitgitignore

提问by Alan Haggai Alavi

I have the following directory structure:

我有以下目录结构:

src/
out/
cout/
...

and I want to ignore out/but not cout/.

我想忽略out/但不是cout/

I've tried putting ^out/, but that doesn't seem to work. I've also tried out/but that also ignores cout/.

我试过 put ^out/,但这似乎不起作用。我也试过,out/但也忽略了cout/.

Any suggestions?

有什么建议?

回答by Alan Haggai Alavi

Exclamation mark(!) should precede a match which should not be ignored.

感叹号 (!) 应位于不应忽略的匹配项之前。

The .gitignorefile should look like:

.gitignore文件应如下所示:

out/
!cout/

回答by Alan Haggai Alavi

Sorry guys, my mistake! The coutdirectory was empty and, therefore, not showing up under git status.

对不起各位,我的错!该cout目录为空,因此未显示在git status.

Just adding out/works fine and doesn't ignore cout/.

只是添加out/工作正常并且不会忽略cout/.

Thanks a lot!

非常感谢!

回答by Jeff Fritz

Which version of git are you using?

你用的是哪个版本的git?

With msysgit 1.6.3-preview20090507-2, the simple

使用 msysgit 1.6.3-preview20090507-2,简单的

out/

works for me. cout/ is still added to the repository.

对我来说有效。cout/ 仍然添加到存储库中。