【问题标题】:How do I "reverse" a gitignore file pattern in a subtree subdirectory?如何“反转”子树子目录中的 gitignore 文件模式?
【发布时间】:2020-02-10 02:45:46
【问题描述】:

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

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

我想忽略来自main 存储库和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

构建/.gitignore

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

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

参考号:Git Subtree Specific Ignoring

干杯

【问题讨论】:

  • 我认为这不可能。一旦忽略子树中的某些内容,就无法在顶层取消忽略它。在链接的 REF 中,情况正好相反——取消忽略顶层忽略的子树中的某些内容;这是可能的,但反过来不行。
  • 感谢您的回答。我将不得不解决其他问题。

标签: git gitignore git-subtree


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-05
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多