tags:

views:

35

answers:

2

I have the following .gitignore file..

*.pyc

project/app/dist/*
project/bin/*
project/etc/*
project/var/*

!README.txt

So far so good, most of my README.txt files are not being ignore, just like i want.. except for project/ect/downloads/README.txt. That file, is being ignored. Why is this? And how can i fix this?

If i remember correctly, i can simply add it to my project manually, but i'd like to learn what i am doing incorrectly in the ignore file.

Thanks to any replies!

+2  A: 

In the .gitignore file, after /project/etc/*, add the 2 lines:

!/project/etc/downloads/
/project/etc/downloads/*
William Pursell
Note: these must come before the `!README.txt` pattern for it to have an affect on the exclusion of `project/etc/downloads/*`
Chris Johnsen
+2  A: 

Git will not search project/etc/downloads/ for any files because you have configured it to ignore project/etc/*. The “unanchored” !README.txt pattern is only good for negating the exclusion of entries in directories that will be searched (i.e. directories that have not themselves been excluded).

If you exclude project/etc/, Git will never search that directory, so negated exclusions can never apply to its contents (not even one so explicit as !project/etc/important-file!—maybe this could be considered a bug?).

However, if you exclude project/etc/*, Git will search that directory, and negated exclusions can apply to its contents. A person might realize that the second pattern will always match all files and assign the same meaning to both patterns, but Git, but Git treats them differently.

You might consider project/etc/ and project/etc/* to mean the same thing, but Git treats them differently because it does not “realize” that the second one will match everything in the directory.

So, to get !README.txt to apply in projects/etc/downloads/ you will have to unignore the directory but ignore its contents before the !README pattern:

project/etc/*

# "unignore, but ignore the immediate contents of" project/etc/downloads
# so that subsequent negated patterns can apply to the immediate contents
!project/etc/downloads/
project/etc/downloads/*

!README.txt
Chris Johnsen
Thanks for the in depth response! I would have never guessed unignore-ignore/* method :)
Lee Olayvar