.gitignore 无法理解我在 Windows 上的文件夹通配符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2330471/
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-15 14:01:19  来源:igfitidea点击:

.gitignore does not understand my folder wildcard on windows

windowsgitmsysgitgitignore

提问by Martin Suchanek

I'm encountering a weird issue with .gitignoreon Windows.

.gitignore在 Windows 上遇到了一个奇怪的问题。

I want git to ignore all .exefiles, except those in the Dependenciesfolder (and all subfolders).

我希望 git 忽略所有.exe文件,除了Dependencies文件夹(和所有子文件夹)中的文件。

So I have:

所以我有:

.gitignore:

.gitignore

*.exe
!/Dependencies/**/*.exe

This, unfortunately, does not work.

不幸的是,这不起作用。

Meanwhile, this does:

同时,这样做:

*.exe
!/Dependencies/folder/subfolder/*.exe

So I'm wondering, am I messing something up, or is this some kind of bug?

所以我想知道,是我搞砸了什么,还是这是某种错误?

I'm running msysgit on Windows (Windows 7 x64) version 1.6.5.1-preview20091022

我在 Windows (Windows 7 x64) 版本 1.6.5.1-preview20091022 上运行 msysgit

Thanks in advance for any input :)

提前感谢您的任何输入:)

回答by VonC

Since git 1.8.2 (March, 8th 2013), the **is now supported:

git 1.8.2 (March, 8th 2013) 开始**现在支持:

The patterns in .gitignoreand .gitattributesfiles can have **/, as a pattern that matches 0 or more levels of subdirectory.

E.g. "foo/**/bar" matches "bar" in "foo" itself or in a subdirectory of "foo".

.gitignore.gitattributes文件中的模式可以**/作为匹配 0 级或更多级子目录的模式

例如,“ foo/**/bar”匹配“ barfoo本身或“ foo”子目录中的“ ”。

In your case, that means this line might now be supported:

在您的情况下,这意味着现在可能支持此行:

!/Dependencies/**/*.exe

回答by jdigital

The .gitignore documentationsays:

的.gitignore文件说:

git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag

git 将模式视为适合 fnmatch(3) 使用 FNM_PATHNAME 标志的 shell glob

It's possible that fnmatch on your platform does not support ** in a path.

您平台上的 fnmatch 可能不支持路径中的 **。

回答by Bram Schoenmakers

You could add a .gitignorefile to the Dependenciesfolder with

您可以将.gitignore文件添加到文件Dependencies夹中

*.exe
*。可执行程序

inside. The obvious downside is that ignore the specifications are scattered among several files now.

里面。明显的缺点是现在忽略了分散在几个文件中的规范。