.gitignore 问题我只需要使用 !*02.* 模式跟踪文件,但我只能排除它们而不使用 !*02.* 跟踪它们

.gitignore issue I need to only track files with !*02.* pattern but I am only able to exclude them not to track them with !*02.*

在 windows 服务器中,每天都会创建一个包含 date\several csv 文件的文件夹。 我只需要提交名称中包含 02. 字符串的文件。

mm-dd-yy\filename02-fdsfsf.csv (ignore this pattern)
mm-dd-yy\data_collection_status (ignore this pattern)
mm-dd-yy\dat (ignore this pattern)
mm-dd-yy\filename02.mmddyy.csv (i want to commit only these types of file)

我创建了一个 .gitignore 文件如下:

*
!.gitignore
!*02.*

当我 运行 git status 时,它只识别 .gitignore 。 测试更改 .gitignore 文件如下:

*02.*
!.gitignore

因此它忽略了具有 02. 模式的文件。 这表明 02. 模式是正确的,那么为什么当我使用 !02. 时它不拒绝它?

非常欢迎任何帮助, 谢谢!

我做了更多测试,似乎 gitignore 文件中的这个模式解决了这个问题:

*
!**/
!*02.*
!.gitignore

谢谢,这很有帮助

根据@torek,如果我们将第二行从 !**/ 更改为 !*/

,它也会起作用

请查看评论,您可以找到@torek 对它如何工作的非常清楚的解释。