git .gitignore:如何忽略嵌套目录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12685134/
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-19 07:34:39  来源:igfitidea点击:

.gitignore: How do I ignore nested directories?

gitgitignore

提问by artagnon

I have the following directory structure:

我有以下目录结构:

test/a
test/b/c
test/a/b/Ouput
test/c/d/e/Output
test/f/Output

I want to ignore all the "Output" directories under "test". I tried test/**/Output, but it didn't work. What am I doing wrong?

我想忽略“测试”下的所有“输出”目录。我试过了test/**/Output,但没有用。我究竟做错了什么?

采纳答案by Chin Huang

You said you want the Output/pattern to match only under the test/directory, so in the test/directory, create a .gitignorefile with the contents:

你说你希望Output/模式只在test/目录下匹配,所以在test/目录中,创建一个.gitignore包含内容的文件:

Output/

If you put this pattern in your top-level .gitignorefile, then it will match in alldirectories under the top directory.

如果将此模式放在顶级.gitignore文件中,那么它将在顶级目录下的所有目录中匹配。

回答by Leszek Jasek

Since version 1.8.2(March, 8th 2013), git supports ** in .gitignorefiles, so using test/**/Output/will ignore only Output sub-directories under test directory.

1.8.2 版本2013 年 3 月 8 日)开始,git 支持.gitignore文件中的** ,因此使用test/**/Output/将仅忽略 test 目录下的 Output 子目录。