2

我有一个包含有一些构建和配置文件的子树的仓库。

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

我想忽略来自回购和子树config.user.json的,但保留在主回购中,但在子树中忽略它。mainbuild config.site.jsonbuild

主/.gitignore

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

构建/.gitignore

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

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

REF:Git 子树特定忽略

干杯

4

1 回答 1

1

它不会那样工作。gitignore 上的 Git 文档说(强调我的)

gitignore 文件中的每一行都指定一个模式。在决定是否忽略路径时,Git 通常会检查来自多个源的 gitignore 模式,按照以下优先顺序,从最高到最低(在一个优先级内,最后匹配的模式决定结果):

  • 从与路径相同的目录或任何父目录中的 .gitignore 文件读取的模式,较高级别文件(直到工作树的顶层)中的模式被低级别文件中的模式覆盖到目录包含文件

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

于 2020-02-21T20:29:04.207 回答