.gitignore不会被.gitignores覆盖到子目录中。项目根目录中的.gitignore

时间:2016-01-04 15:01:46

标签: git tortoisegit

在项目根目录中,我有.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。 “儿童”gitignore不工作的原因可能是什么?

1 个答案:

答案 0 :(得分:2)

注意:要检查文件是否被忽略,请使用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 +)中满足某些条件

这意味着,当您排除所有内容(&#39; *&#39;)时,您必须列出白名单文件夹,然后才能列出白名单文件。

# Ignore everything under node_modules
*

# Except for the subfolders
!**/

# Except for the .gitignore
!.gitignore

然后在implementation\xml中,您可以从.gitignore中排除文件(因为其文件夹和子文件夹已经列入白名单)

implementation\xml\.gitignore:

!*