3

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

lisinan
  • 61
  • 6
  • 1
    Possible duplicate of [Git: inverse ignoring (.gitignore)](https://stackoverflow.com/questions/13398648/git-inverse-ignoring-gitignore) – Andreas Feb 15 '19 at 04:02

2 Answers2

5

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.

Dharman
  • 26,923
  • 21
  • 73
  • 125
vauhochzett
  • 1,883
  • 1
  • 15
  • 31
3

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

*
!/app/
!/app/*
phd
  • 69,888
  • 11
  • 97
  • 133