git git忽略多个匹配文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7947071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git ignore multiple matching files
提问by michael nesterenko
I try to ignore file in a directory by relative path. E.g. I have several directories in working tree lib/file.f
and I want all occurrences of this file to be ignored. I tried
我尝试通过相对路径忽略目录中的文件。例如,我在工作树中有几个目录,lib/file.f
我希望忽略此文件的所有出现。我试过
lib/file.f
but this does not work.
但这不起作用。
回答by unutbu
Place
地方
*/lib/file.f
in your .gitignore
. This will cause git to ignore any file of the form project/<DIR>/lib/file.f
, assuming .gitignore
is in the project
directory.
To make git ignore lib/file.f
two directories down, you'd also have to add
在您的.gitignore
. 这将导致 git 忽略表单的任何文件project/<DIR>/lib/file.f
,假设.gitignore
在project
目录中。要使 git 忽略lib/file.f
两个目录,您还必须添加
*/*/lib/file.f
to the .gitignore
, and so on.
到.gitignore
,等等。
Vastly simpler of course, would be to place
当然要简单得多,就是放置
*file.f
in .gitignore
to block all files named file.f
, but your question seems to suggest there is at least one file by that name you wish not to ignore.
in.gitignore
阻止所有名为 的文件file.f
,但您的问题似乎表明至少有一个该名称的文件您不想忽略。
回答by cclaudiu
also you might want to remove the file from git cache, in order to check what you just ignored:
您也可能想从 git 缓存中删除该文件,以检查您刚刚忽略的内容:
git rm --cached lib/file.f
this is if you already added the file to git index
这是如果您已经将文件添加到 git index
回答by petrsyn
If you want to specify all sub-folders under specific folder use /**/
. To ignore all file.f
files in a /src/main/
folder and sub-folders use:
如果要指定特定文件夹下的所有子文件夹,请使用/**/
. 要忽略file.f
文件/src/main/
夹和子文件夹中的所有文件,请使用:
/src/main/**/file.f