我如何 "reverse" 子树子目录中的 gitignore 文件模式?

How do I "reverse" a gitignore file pattern in a subtree subdirectory?

我有一个包含子树的存储库,其中包含一些构建和配置文件。

main
├── .gitignore
└── build (subtree)
    ├── .gitignore
    └── config.user.json
    └── config.site.json
└── index.js

我想忽略来自main repo和build子树的config.user.json,但是保持 config.site.json 在主仓库中,但 忽略 它在 build 子树中。

main/.gitignore

!build/config.site.json # (this is supposed to reverse the ignore)
build/config.user.json

build/.gitignore

build/config.site.json
build/config.user.json

这可能吗,或者我应该将我的配置文件放在 build 不同的文件夹中。我有一种感觉,子树中的 .gitignore 将覆盖主仓库中的 .gitignore,而不是相反。

REF:

干杯

那样做是行不通的。 gitignore 上的 Git 文档说(强调我的)

Each line in a gitignore file specifies a pattern. When deciding whether to ignore a path, Git normally checks gitignore patterns from multiple sources, with the following order of precedence, from highest to lowest (within one level of precedence, the last matching pattern decides the outcome):

  • Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file.

https://git-scm.com/docs/gitignore