忽略git中具有相同名称的所有文件

Cha*_*erj 30 git gitignore

有没有办法git ignore file忽略所有名称为test的文件?

我有这样的文件:

 - css/test.css 
 - js/subfolder/test.js 
 - lib/main/sub/test.html
Run Code Online (Sandbox Code Playgroud)

等等.

我想git避免使用名称test添加或提交任何文件.

Ale*_*.K. 47

来自git docs

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".
Run Code Online (Sandbox Code Playgroud)

对于你的情况:

**/[Tt]est*
Run Code Online (Sandbox Code Playgroud)

它也匹配大小写.

  • @clabe45 a * 是一个特殊字符,表示任意数量(包括零)的任意字符。因此,在这种情况下,它将匹配“test.json”、“test.py”、“testosterone”、“testimony.txt.jpg.zip”,甚至只是“test”。您可以尝试使用句点执行“**/[Tt]est.*”,尽管这不会捕获“testClient.js”等文件。 (3认同)
  • 后面的“*”有什么作用? (2认同)

Jam*_*sev 26

更新.gitignoretest*

另请阅读此内容以获取更多信息.

  • 为什么这么多票呢?正确的似乎是"**/.."与两颗起始星.该链接也不是指2星.`test*`只在基础目录中忽略它. (7认同)
  • 来自“man gitignore”:“前导“**”后跟斜杠表示在所有目录中匹配。例如,“**/foo”在任何地方匹配文件或目录“foo”,与模式“foo”相同。“**/foo/bar”匹配直接位于目录“foo”下的任何位置的文件或目录“bar”。 (3认同)

Dav*_*e G 5

尝试将模式添加到测试的.gitignore。*

添加它,并对上面提到的某些文件进行git状态处理。

如果可行,那就很好。