Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore does not understand my folder wildcard on windows

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 :)

like image 654
Martin Suchanek Avatar asked Feb 24 '10 23:02

Martin Suchanek


People also ask

How do I use wildcards in Gitignore?

gitignore is a plain text file in which each line contains a pattern for files or directories to ignore. It uses globbing patterns to match filenames with wildcard characters. If you have files or directories containing a wildcard pattern, you can use a single backslash ( \ ) to escape the character.

Can Gitignore ignore a folder?

Inside . gitignore , you can tell Git to ignore only a single file or a single folder by mentioning the name or pattern of that specific file or folder. You can also tell Git to ignore multiple files or folders using the same method.

Does Gitignore work in folder?

gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple . gitignore files.


2 Answers

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

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".

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

!/Dependencies/**/*.exe
like image 56
VonC Avatar answered Oct 20 '22 22:10

VonC


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.

like image 2
jdigital Avatar answered Oct 20 '22 21:10

jdigital