I have the folder application/
which I add to the .gitignore
. Inside the application/
folder is the folder application/language
Commit 59856de from Karsten Blees (kblees) for Git 1.9/2.0 (Q1 2014) clarifies that case:
An optional prefix "
!
" which negates the pattern; any matching file excluded by a previous pattern will become included again.It is not possible to re-include a file if a parent directory of that file is excluded. (
*
)
(*
: unless certain conditions are met in git 2.8+, see below)
Git doesn't list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.Put a backslash ("
\
") in front of the first "!
" for patterns that begin with a literal "!
", for example, "\!important!.txt
".Example to exclude everything except a specific directory
foo/bar
(note the/*
- without the slash, the wildcard would also exclude everything withinfoo/bar
):
--------------------------------------------------------------
$ cat .gitignore
# exclude everything except directory foo/bar
/*
!/foo
/foo/*
!/foo/bar
--------------------------------------------------------------
In your case:
application/*
!application/**/
application/language/*
!application/language/**/
!application/language/gr/**
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:
application/
!application/language/gr/