git gitignore 目录和子目录中的所有文件(特定文件类型)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28539446/
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
gitignore all files (specific filetype) in a directory and subdirectories
提问by michbeck
What's the right way to ignore a certain filetype in a certain directory and all subdirectories in it?
忽略某个目录及其所有子目录中的某个文件类型的正确方法是什么?
Example: ignore all .xml
files in master/xyz/
and all subdirectories in master/xyz/
.
例如:忽略所有.xml
的文件master/xyz/
和所有子目录中master/xyz/
。
I'm not sure which of the following two approaches is the right one...
我不确定以下两种方法中的哪一种是正确的...
master/xyz/*/*.xml
master/xyz/**/*.xml
Which one should I use?
我应该使用哪一种?
(I use Git 1.9.1)
(我使用 Git 1.9.1)
回答by acanby
You can add something like this, it will work as of git 1.8.2.1 (documentation here)
你可以添加这样的东西,它可以从 git 1.8.2.1 开始工作(文档在这里)
A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
斜杠后跟两个连续的星号,然后斜杠匹配零个或多个目录。例如,“a/**/b”匹配“a/b”、“a/x/b”、“a/x/y/b”等。
# should work
master/xyz/**/*.xml
The first suggestion you posted won't work as it will not match anything (as it is a literal)
您发布的第一个建议不起作用,因为它不匹配任何内容(因为它是文字)
# wont work
master/xyz//.xml