How do negated patterns work in .gitignore?
Solution 1:
I think that what you actually want to do is:
aaa/*
!aaa/ccc
You're telling it "don't look in aaa
" so it never even examines the path aaa/ccc
. If you use the wildcard, it still reads the contents of aaa
, then each entry matches the wildcard and is ignored, except aaa/ccc
which gets put back in.
Solution 2:
If you want to exclude everything in aaa
, but include aaa/ccc
and everything beneath it, you should use:
aaa/*
!aaa/ccc
!aaa/ccc/*
The first line tells git to ignore everthing beneath aaa
, the second tells it not to ignore the folder aaa/ccc
which actually "enables" the third line which then tells it not to ignore everything beneath aaa/ccc
.
Solution 3:
If anyone's still not seeing newly un-ignored items in a git status
running a git update-index
before hand can help git to see the changes (at least in version 1.9.x of gitbash).