如何添加一些东西到.gitignore,以便匹配不递归? [英] How to I add something to the .gitignore so that the match is not recursive?
问题描述
如何向 .gitignore
添加一些内容,以便匹配不是递归的?
例如,我希望忽略当前目录中的 foo
目录和文件 bar.txt
,但不存在任何目录在我的 .gitignore
文件中:
foo /
bar.txt
但不幸的是git会递归地应用这个,所以 otherdir / bar.txt
和 otherdir / foo /
忽略,这不是我想要的。
(git中是否有一个命令显示所有被忽略的文件,并引用 .gitignore
文件是负责被忽略的文件吗?这对调试很有用。)
解决方案是在 .gitignore
条目上放置一个斜杠:
/ foo /
/bar.txt
(我以为我在发布StackOverflow之前尝试了这个,但显然我没有正确地尝试过,因为它完美无缺。)
How to I add something to the .gitignore
so that the match is not recursive?
For example, I wish to ignore the directory foo
and the file bar.txt
in the current directory, but not any that exist in subdirectories.
I have tried this for my .gitignore
file:
foo/
bar.txt
But unfortunately git applies this recursively, so that otherdir/bar.txt
and otherdir/foo/
also get ignored, which is not what I want.
(Is there a command in git that shows me all ignored files, and reference the .gitignore
file that is responsible for the file being ignored? This would be useful for debugging.)
The solution is to place a leading slash on the .gitignore
entries:
/foo/
/bar.txt
(I thought I tried this before posting on StackOverflow, but clearly I hadn't tried it properly, as this works perfectly.)
这篇关于如何添加一些东西到.gitignore,以便匹配不递归?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!