不忽略子目录中的文件? [英] Not ignore a file in a sub directory?
问题描述
我有以下 .gitignore
文件
*。pyc
project / app / dist / *
project / bin / *
项目/ etc / *
项目/ var / *
!README.txt
到目前为止,我的大多数 README.txt
文件不会被忽略,就像我希望除 project / ect / downloads / README.txt
一样。该文件被忽略。为什么是这样?我怎样才能解决这个问题?
如果我没有记错,我可以简单地将它添加到我的项目中,但我想知道我在做什么不正确忽略文件。
Git不会搜索项目/ etc / downloads /
对于任何文件,因为您已将其配置为忽略项目/ etc / *
。 unanchored!README.txt
模式仅适用于否定排除将要搜索的目录中的条目(即,本身未被排除的目录)。 p>
如果你排除项目/ etc /
,Git将永远不会搜索该目录,所以否定排除不能应用于其内容(甚至没有一个像!project / etc / important-file
这样明确的! - 也许这可能被认为是一个错误?)。
$ b但是,如果排除项目/ etc / *
,Git将搜索该目录,否定排除可应用于其内容。一个人可能会意识到,第二种模式将始终匹配所有文件并为这两种模式分配相同的含义,但Git,但Git会以不同的方式处理它们。您可能会考虑项目/ etc /
和项目/ etc / *
意味着同样的事情,但Git以不同的方式对待它们,因为它没有意识到第二个匹配目录中的所有内容。
因此,要获取!README.txt
要在项目/ etc / downloads /
中应用,您必须取消管理该目录,但在!README
之前忽略其内容,模式:
项目/ etc / *
#unignore,但忽略 project / etc / downloads / *
$ b $项目/ etc / downloads
#这样后续的否定模式可以应用于直接的内容
!project / etc / downloads /
项目/ etc / downloads / *
!README.txt
I have the following .gitignore
file
*.pyc
project/app/dist/*
project/bin/*
project/etc/*
project/var/*
!README.txt
So far so good, most of my README.txt
files are not being ignored, just like I want it to happen except for project/ect/downloads/README.txt
. That file, is being ignored. Why is this? And How can I fix this?
If I remember correctly, I can simply add it to my project manually, but I'd like to learn what I am doing incorrectly in ignoring the file.
Git will not search project/etc/downloads/
for any files because you have configured it to ignore project/etc/*
. The "unanchored" !README.txt
pattern is only good for negating the exclusion of entries in directories that will be searched (i.e. directories that have not themselves been excluded).
If you exclude project/etc/
, Git will never search that directory, so negated exclusions can never apply to its contents (not even one so explicit as !project/etc/important-file
!—maybe this could be considered a bug?).
However, if you exclude project/etc/*
, Git will search that directory, and negated exclusions can apply to its contents. A person might realize that the second pattern will always match all files and assign the same meaning to both patterns, but Git, but Git treats them differently.
You might consider project/etc/
and project/etc/*
to mean the same thing, but Git treats them differently because it does not "realize" that the second one will match everything in the directory.
So, to get !README.txt
to apply in projects/etc/downloads/
you will have to unignore the directory but ignore its contents before the !README
pattern:
project/etc/*
# "unignore, but ignore the immediate contents of" project/etc/downloads
# so that subsequent negated patterns can apply to the immediate contents
!project/etc/downloads/
project/etc/downloads/*
!README.txt
这篇关于不忽略子目录中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!