进入项目根目录的 .gitignore 不会被进入 children 目录的 .gitignores 覆盖
.gitignore into the project root directory is not overriden by .gitignores into children directories
在项目根目录中,我有 .gitignore
文件,它会忽略除 gitignore 文件之外的所有内容。这是文件的内容:
**/*
!.gitignore
然后在 implementation/xml/
我有另一个包含以下内容的 gitignore 文件:
!**/*
然后在 implementation/xml/ant/ 我创建了一个名为 texd-odt-build.xml
完整路径的新文件 (/implementation/xml/ant/texd-odt-build.xml).
现在是第二个 gitignore 文件,它位于项目根目录中的文件(gitignore 文件)之下的两个文件夹中。那么第二个 gitignore 应该覆盖根目录中的那个吗?但是使用 bash 我看到 texd-odt-build.xml
仍然在忽略列表中。
为了检查它,我使用了这个命令:git status --ignored
。 “children”gitignore 不工作的原因可能是什么?
注意:要检查文件是否被忽略,请使用 git check-ignore
:
git check-ignore -v -- afile
正如我在“How do I add files without dots in them (all extension-less files) to the gitignore
file?”中提到的,主要有一条规则需要记住.gitignore
:
It is not possible to re-include a file if a parent directory of that file is excluded. (†
)
(†
:除非在git 2.7+中满足某些条件)
这意味着,当您排除所有内容 ('*
') 时,您必须先 white-list 个文件夹,然后才能 white-list 个文件。
# Ignore everything under node_modules
*
# Except for the subfolders
!**/
# Except for the .gitignore
!.gitignore
然后在 implementation\xml
中,您可以从 .gitignore
中排除文件(因为它的文件夹和 sub-folders 已经 white-listed)
implementation\xml\.gitignore:
!*
在项目根目录中,我有 .gitignore
文件,它会忽略除 gitignore 文件之外的所有内容。这是文件的内容:
**/*
!.gitignore
然后在 implementation/xml/
我有另一个包含以下内容的 gitignore 文件:
!**/*
然后在 implementation/xml/ant/ 我创建了一个名为 texd-odt-build.xml
完整路径的新文件 (/implementation/xml/ant/texd-odt-build.xml).
现在是第二个 gitignore 文件,它位于项目根目录中的文件(gitignore 文件)之下的两个文件夹中。那么第二个 gitignore 应该覆盖根目录中的那个吗?但是使用 bash 我看到 texd-odt-build.xml
仍然在忽略列表中。
为了检查它,我使用了这个命令:git status --ignored
。 “children”gitignore 不工作的原因可能是什么?
注意:要检查文件是否被忽略,请使用 git check-ignore
:
git check-ignore -v -- afile
正如我在“How do I add files without dots in them (all extension-less files) to the gitignore
file?”中提到的,主要有一条规则需要记住.gitignore
:
It is not possible to re-include a file if a parent directory of that file is excluded. (†
)
(†
:除非在git 2.7+中满足某些条件)
这意味着,当您排除所有内容 ('*
') 时,您必须先 white-list 个文件夹,然后才能 white-list 个文件。
# Ignore everything under node_modules
*
# Except for the subfolders
!**/
# Except for the .gitignore
!.gitignore
然后在 implementation\xml
中,您可以从 .gitignore
中排除文件(因为它的文件夹和 sub-folders 已经 white-listed)
implementation\xml\.gitignore:
!*