问题
I'm encountering a weird issue with .gitignore on Windows.
I want git to ignore all .exe files, except those in the Dependencies folder (and all subfolders).
So I have:
.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
Thanks in advance for any input :)
回答1:
Since git 1.8.2 (March, 8th 2013), the ** is now supported:
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".
In your case, that means this line might now be supported:
!/Dependencies/**/*.exe
回答2:
The .gitignore documentation says:
git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag
It's possible that fnmatch on your platform does not support ** in a path.
回答3:
You could add a .gitignore file to the Dependencies folder with
*.exe
inside. The obvious downside is that ignore the specifications are scattered among several files now.
来源:https://stackoverflow.com/questions/2330471/gitignore-does-not-understand-my-folder-wildcard-on-windows