Is there a way to ignore all files of a type in a directory?
**
is apparently meaningless to git, so this doesn't work:
/public/static/**/*.js
The idea is to match arbitrary nested folders.
Is there a way to ignore all files of a type in a directory?
**
is apparently meaningless to git, so this doesn't work:
/public/static/**/*.js
The idea is to match arbitrary nested folders.
UPDATE: Take a look at @Joey's answer: Git now supports the
**
syntax in patterns. Both approaches should work fine.The gitignore(5) man page states:
What this means is that the patterns in a
.gitignore
file in any given directory of your repo will affect that directory and all subdirectories.The pattern you provided
isn't quite right, firstly because (as you correctly noted) the
**
syntax is not used by Git. Also, the leading/
anchors that pattern to the start of the pathname. (So,/public/static/*.js
will match/public/static/foo.js
but not/public/static/foo/bar.js
.)Removing the leadingEDIT: Just removing the leading slash won't work either — because the pattern still contains a slash, it is treated by Git as a plain, non-recursive shell glob (thanks @Joey Hoer for pointing this out)./
won't work either, matching paths likepublic/static/foo.js
andfoo/public/static/bar.js
.As @ptyx suggested, what you need to do is create the file
<repo>/public/static/.gitignore
and include just this pattern:There is no leading
/
, so it will match at any part of the path, and that pattern will only ever be applied to files in the/public/static
directory and its subdirectories.It would appear that the
**
syntax is supported bygit
as of version1.8.2.1
according to the documentation.To ignore untracked files just go to .git/info/exclude. Exclude is a file with a list of ignored extensions or files.
Never tried it, but
git help ignore
suggests that if you put a.gitignore
with*.js
in/public/static
, it will do what you want.Note: make sure to also check out Joeys' answer below: if you want to ignore files in a specific subdirectory, then a local .gitignore is the right solution (locality is good). However if you need the same pattern to apply to your whole repo, then the ** solution is better.
I believe the simplest solution would be to use
find
. I do not like to have multiple.gitignore
hanging around in sub-directories and I prefer to manage a unique, top-level.gitignore
. To do so you could simply append the found files to your.gitignore
. Supposing that/public/static/
is your project/git home I would use something like:I found that cutting out the
./
at the beginning is often necessary for git to understand which files to avoid. Therefore thecut -c 3-
.