views:

1026

answers:

2

Anyone know if it is possible to ignore all the instances of a particular directory in a file structure managed by git.

I'm looking to exclude all the 'target' folders in a maven project with a number of submodules. I know I can explicitly exclude each of them in a top level .gitignore, but I'd really like to be able to specify a pattern like **/target/* there to have it automatically ignore the instance in sub directories?

Is this possible?

tia,

ste

+3  A: 

It is possible to use patterns in a .gitignore file. See the gitignore man page. The pattern */target/* should ignore any directory named target and anything under it.

docgnome
sgargan
With what configuration are you making this work? */.settings/* would only ignore 'xxx/.settings/*', not '.settings/*' or 'xxx/yyy/.settings/*': the ignore patterns do not seem to be applied recursively. See also http://stackoverflow.com/questions/971465/git-ignore-certain-files-contained-in-specific-folders .
VonC
+7  A: 

The .gitignore file in the root directory does apply to all subdirectories. Mine looks like this:

.classpath
.project
.settings/
target/

This is in a multi-module maven project. All the submodules are imported as individual eclipse projects using m2eclipse. I have no further .gitignore files. Indeed, if you look in the gitignore man page:

Patterns read from a .gitignore file in the same directory as the path, or in any parent directory

So this should work for you.

Dominic Mitchell
That is a better answer than '*/target/*'. It does exclude a directory wherever it is located in the tree of directories. But it would not work for files (see http://stackoverflow.com/questions/971465/git-ignore-certain-files-contained-in-specific-folders )
VonC
(+1 by the way).
VonC