I have the folder application/ which I add to the .gitignore. Inside the application/ folder is the folder application/language/gr. How can I include this folder? I've tried this
application/
!application/language/gr/
with no luck...
I have the folder application/ which I add to the .gitignore. Inside the application/ folder is the folder application/language/gr. How can I include this folder? I've tried this
application/
!application/language/gr/
with no luck...
If you exclude
application/
, then everything under it will always be excluded (even if some later negative exclusion pattern (“unignore”) might match something underapplication/
).To do what you want, you have to “unignore” every parent directory of anything that you want to “unignore”. Usually you end up writing rules for this situation in pairs: ignore everything in a directory, but not some certain subdirectory.
Note
The trailing
/*
is significant:dir/
excludes a directory nameddir
and (implicitly) everything under it.With
dir/
, Git will never look at anything underdir
, and thus will never apply any of the “un-exclude” patterns to anything underdir
.dir/*
says nothing aboutdir
itself; it just excludes everything underdir
. Withdir/*
, Git will process the direct contents ofdir
, giving other patterns a chance to “un-exclude” some bit of the content (!dir/sub/
).I have found a similar case here, where in laravel by default,
.gitignore
ignores all using asterix, then overrides the public directory.This is not sufficient if you run into the OP scenario.
If you want to commit a specific subfolders of
public
, say for e.g. in yourpublic/products
directory you want to include files that are one subfolder deep e.g. to includepublic/products/a/b.jpg
they wont be detected correctly, even if you add them specifically like this!/public/products
,!public/products/*
, etc..The solution is to make sure you add an entry for every path level like this to override them all.
In WordPress, this helped me:
I wanted to track jquery production js files and this worked:
gitignore - Specifies intentionally untracked files to ignore.
Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):
Another example for WordPress:
More informations in here: https://git-scm.com/docs/gitignore
Commit 59856de from Karsten Blees (kblees) for Git 1.9/2.0 (Q1 2014) clarifies that case:
gitignore.txt
: clarify recursive nature of excluded directoriesIn your case:
You must white-list folders first, before being able to white-list files within a given folder.
Update Feb/March 2016:
Note that with git 2.9.x/2.10 (mid 2016?), it might be possible to re-include a file if a parent directory of that file is excluded if there is no wildcard in the path re-included.
Nguyễn Thái Ngọc Duy (
pclouds
) is trying to add this feature:So with git 2.9+, this could have actually worked, but was ultimately reverted: