tags:

views:

40

answers:

1

For various reasons, I have the entry in my .gitignore in the root of a project:

 *.c

As I desire, this ignores all C files from being included. However, I really only want the C files to only be ignored in the root directory, and not all the sub-directories:

 foo.c
 bar.c
 folder/baz.c

In the above scheme, I only want foo.c and bar.c ignored. I do not want this gitignore rule to work recursively. How do I do this?

I'm aware of being able to negate the rule with !*.c, but I'd rather not do that for every subdirectory. (This is what I am currently doing).

+5  A: 

You want to do this:

/*.c

I was looking for a bit from the manpage to quote, and found that this exact example's in there! Oops!

A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".

Jefromi
Fantastic. Thanks.
carl