I have a structure similar to the following:
/root/
/root/data/
/root/data/script.php
/root/data/some.json
/root/data/feature/one.json
/root/data/feature/two.json
/root/data/other-feature/one.json
/root/data/other-feature/important-script.php
I’d like git to ignore any .json files under the ‘/data/…’ path, but ‘/data/’ sometimes contains sub-directories.
My understanding is that a simple data/*.json in gitignore will only match one directory, as the * doesn’t match /, as stated at http://git-scm.com/docs/gitignore, “Pattern Format”, bullet #6:
Otherwise, 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”.
Is there a simple way to do this, or do I need to actively add gitignore files in each sub-directory, explicitly?
I’ve written a post about such problem recently. See here.
Basically what you need is to put one
.gitignorewith*.jsonin the/data/directory.UPD: Since git 1.8.4 (1.8.2 if you’re using msysgit) it is possible to use double-star patterns, like
/data/**/*.json