From: Jason Cooper Date: Fri, 26 Oct 2018 15:27:54 GMT Subject: Re: the opposite of .gitignore, whitelist Message-ID: <20181026152754.GF24185@io.lakedaemon.net> In-Reply-To: <20181026133453.GE24185@io.lakedaemon.net> On Fri, Oct 26, 2018 at 01:34:53PM +0000, Jason Cooper wrote: > On Fri, Oct 26, 2018 at 02:39:26PM +0200, Ævar Arnfjörð Bjarmason wrote: ... > > I thought this was a bug: > > > > ( > > rm -rf /tmp/git && > > git init /tmp/git && > > cd /tmp/git >/dev/null && > > echo '*' >.gitignore && > > echo '!*.txt' >>.gitignore && > > echo '!.gitignore' >>.gitignore && > > touch foo.png foo.txt && > > mkdir dir && > > touch dir/bar.png dir/bar.txt && > > git add *.txt && > > git add */*.txt; > > git status --short > > ) > > > > But it's a limitation, gitignore(5) says: > > > > It is not possible to re-include a file if a parent directory of > > that file is excluded. Git doesn’t list excluded directories for > > performance reasons, so any patterns on contained files have no > > effect, no matter where they are defined. > > Bingo. This is the exact problem I encountered. ( rm -rf /tmp/git && git init /tmp/git && cd /tmp/git >/dev/null && echo '*' >.gitignore && echo '!dir/' >>.gitignore && echo '!*.txt' >>.gitignore && echo '!.gitignore' >>.gitignore && touch foo.png foo.txt && mkdir dir && echo '*' >dir/.gitignore && echo '!*.txt' >>dir/.gitignore && echo '!.gitignore' >>dir/.gitignore && touch dir/bar.png dir/bar.txt && git add *.txt && git add */*.txt; git status --short ) Well, this wfm... Ugly, but doable. thx, Jason.