19

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

Martin Suchanek
  • 3,006
  • 6
  • 31
  • 31

3 Answers3

21

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
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
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.

jdigital
  • 11,926
  • 4
  • 34
  • 51
  • 1
    @jdigital This is what I suspected (feared, really) as well. If this is the case, then it could potentially wreck havoc in cross-platform repos :( – Martin Suchanek Feb 25 '10 at 00:32
2

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.

Bram Schoenmakers
  • 1,599
  • 14
  • 19
  • 2
    Why was this answer accepted and upvoted? The question was how to ignore `*.exe` files **except** for those inside `Dependencies/`. – Adam Spiers Mar 06 '13 at 14:47