【问题标题】:.gitignore negation not working.gitignore 否定不起作用
【发布时间】:2022-02-10 05:27:32
【问题描述】:

我正在使用 msysgit 1.9.4。

我的 .gitignore 文件,位于 repo 的根目录,如下所示:

build/
a/b/
!a/c/d/e/**/build/

我的意图是,所有 build/ 目录都被忽略,除非它们是 a/c/d/e/ 的子目录(任何深度)。 但是 a/c/d/e/f/build/ 仍然被 Git 忽略。

我在这里错过了什么?

【问题讨论】:

  • 您是否有其他 git ignore 规则被选中?除了从 gitignore 文件中获取规则外,它还可能从树中的其他 gitignore 文件、$GIT_DIR/info/exclude 或配置变量 core.excludesfile 中读取规则。见git-scm.com/docs/gitignore#
  • @Chris,谢谢,但它不是重复的,我不排除我想要包含的文件夹被忽略的文件夹。编辑:为了澄清,a/c/d/e/f/ 被包括在内,但是当我想要它包括时 a/c/d/e/f/build/ 被忽略。
  • @jkyako,不,repo中没有其他gitignore文件,.git/info/exclude为空,core.excludesfile没有分配。
  • @ErikaE,git check-ignore -v a/c/d/e/f/build/ 显示什么?使用build/ 中的文件而不是目录本身的相同命令呢?

标签: git gitignore msysgit


【解决方案1】:

gitignore 的一般规则很简单:

It is not possible to re-include a file if a parent directory of that file is excluded.

要从被忽略文件夹build 的子文件夹中排除文件(或所有文件),需要先排除文件夹,然后排除文件:

我已经测试过:

**/build/
a/b/
!a/c/d/e/**/build/     <== whitelist folder first
!a/c/d/e/**/build/**   <== then the files

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多