git 忽略git中所有同名文件

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

Ignore all files with the same name in git

gitgitignore

提问by Chapsterj

Is there a way to have a git ignore fileto ignore all files with the name test in them?

有没有办法让 agit ignore file忽略其中包含名称 test 的所有文件?

I have files like this:

我有这样的文件:

 - css/test.css 
 - js/subfolder/test.js 
 - lib/main/sub/test.html

and so on.

等等。

I want gitto avoid adding or committing any files with the name test.

我想git避免添加或提交任何名称为 test 的文件。

采纳答案by James Raitsev

Update .gitignorewith test*

更新.gitignoretest*

Also, read thisfor more information.

另外,请阅读本文以获取更多信息。

回答by Alex.K.

From git docs

来自git 文档

A leading "**" followed by a slash means match in all directories. For
example, "**/foo" matches file or directory "foo" anywhere, the same
as pattern "foo". "**/foo/bar" matches file or directory "bar"
anywhere that is directly under directory "foo".

For your case:

对于您的情况:

**/[Tt]est*

it also matches both upper and lower case.

它还匹配大小写。

回答by Dave G

Try adding the pattern to .gitignore of test.*

尝试将模式添加到 test.gitignore 中。*

Add it and do a git status with some files like you mentioned above.

添加它并使用上面提到的一些文件执行 git status 。

If it works you're good.

如果它有效,你就很好。