如何向 .gitignore 添加一些内容以使匹配不递归?
如何向 .gitignore
添加一些内容以使匹配不是递归的?
例如,我希望忽略当前目录中的目录 foo
和文件 bar.txt
,但不忽略子目录中存在的任何文件。
我已经为我的 .gitignore 文件尝试过这个:
foo/
bar.txt
但不幸的是 git 递归地应用这个,因此 otherdir/bar.txt 和 otherdir/foo/也被忽视,这不是我想要的。
(git 中是否有一个命令可以显示所有被忽略的文件,并引用导致该文件被忽略的 .gitignore
文件?这对于调试很有用。)
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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案是在
.gitignore
条目上放置一个前导斜杠:(我以为我在 StackOverflow 上发布之前尝试过此操作,但显然我没有正确尝试过,因为这非常有效。)
The solution is to place a leading slash on the
.gitignore
entries:(I thought I tried this before posting on StackOverflow, but clearly I hadn't tried it properly, as this works perfectly.)
来自 gitignore 联机帮助页:
因此
!*
作为 .gitignore 中的第一行将清除所有以前的模式。From the gitignore manpage:
So
!*
as the first line in your .gitignore will clear all previous patterns.