- Home /
Make git ignore *_Data/ build output
This is git specific. I'd like my .gitignore file to ignore directories of the form *_Data/
that are created after a Unity build.
I have the following line in my .gitignore file
*_Data/ # ignore executable data directories
But when i do git add *
, the entire directory gets added. What am I doing wrong?
Answer by rutter · Sep 25, 2014 at 07:37 PM
The short answer is that your pattern should use a special **
wildcard:
**_Data/
If you check the gitignore docs they do mention the following:
Git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname. For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".
If you're like me, you probably dread reading Git's docs. More often than that, you walk in with one question and walk out with twenty.
Still, at least we now know that you've run into one of the common gotchas about glob patterns: you expect the *
wildcard to work on the entire path, but it only really works on the right-most part.
You might think: if *.html
matches all HTML files, shouldn't *_content/*.html
match all HTML files in my content folders? Sadly, no. You need a special wildcard to include folder names in the search pattern.
In your case, that would look something like this:
**_Data/
I did try that actually :)
When I say git add *
from the root of my repo, would it override my .gitignore and add the directory regardless?
never$$anonymous$$d, i had added **_Data/ #ignore exe data dir
the space after /
prevented the line from actively filtering such dirs.