Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use .gitignore reverse select

Tags:

git

gitignore

use .gitignore to reverse selection,I just want to track the app catalog.App is the secondary directory under emply.

enter image description here

l used The following code,But git doesn't track anything

*
!*/
!*/app

I have already tested similar problems, Write like it, but invalid

like image 760
lisinan Avatar asked Oct 18 '25 10:10

lisinan


2 Answers

I just had a slightly more tricky problem and ended up here, so if this is the case for you as well, here goes:

If you ignore a concrete directory (e.g. /Emply/ in this case) but want to include some of its sub-directories or included files, this will not work:

/Emply/
!/Emply/app  # Does not work!

The reason is that git will not list ignored directories for performance reasons (source). Instead, use the wildcard to ignore all sibling directories and files:

/Emply/*
!/Emply/app  # Works!

It's a bit obscure and just drove me mad.

like image 189
vauhochzett Avatar answered Oct 20 '25 01:10

vauhochzett


Ignore everything, unignore top-level app and everything under it:

*
!/app/
!/app/*
like image 20
phd Avatar answered Oct 19 '25 23:10

phd