.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
.gitignore does not understand my folder wildcard on windows
提问by Martin Suchanek
I'm encountering a weird issue with .gitignore
on Windows.
我.gitignore
在 Windows 上遇到了一个奇怪的问题。
I want git to ignore all .exe
files, except those in the Dependencies
folder (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
.gitignore
and.gitattributes
files 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
”匹配“bar
”foo
本身或“foo
”子目录中的“ ”。
In your case, that means this line might now be supported:
在您的情况下,这意味着现在可能支持此行:
!/Dependencies/**/*.exe
回答by jdigital
The .gitignore documentationsays:
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 .gitignore
file to the Dependencies
folder with
您可以将.gitignore
文件添加到文件Dependencies
夹中
*.exe
*。可执行程序
inside. The obvious downside is that ignore the specifications are scattered among several files now.
里面。明显的缺点是现在忽略了分散在几个文件中的规范。