使用 .gitignore 忽略不同文件夹中的相同文件

Ignore same file in different folders with .gitignore

我如何使用 .gitignore 来忽略可以位于多个文件夹中且同名的文件?

我有

-folderA -folderAA -file.json -folderB -folderBB -file.json

我需要的是一个表达式来忽略 folderA/folderAA 和 [=24= 中的 file.json ]folderB/folderBB 而不必为每个文件使用两个表达式。

编辑开始
该文件已被 git
跟踪 编辑结束

您可以使用**通配符指定任何目录

例如: **/file.json

只需将 file.json 添加到没有任何前缀的 .gitignore 中即可。

基于此处的 Git 文档 (http://git-scm.com/docs/gitignore) :

/**/file.json

如果 JSON 文件有不同的名称,请考虑使用 /**/*.json 但要小心,这将排除所有 JSON 文件