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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:07:50  来源:igfitidea点击:

git ignore multiple matching files

git

提问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.fand 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 .gitignoreis in the projectdirectory. To make git ignore lib/file.ftwo directories down, you'd also have to add

在您的.gitignore. 这将导致 git 忽略表单的任何文件project/<DIR>/lib/file.f,假设.gitignoreproject目录中。要使 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 .gitignoreto 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.ffiles in a /src/main/folder and sub-folders use:

如果要指定特定文件夹下的所有子文件夹,请使用/**/. 要忽略file.f文件/src/main/夹和子文件夹中的所有文件,请使用:

/src/main/**/file.f