4

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
  • 71
  • 7
  • 1
    Possible duplicate of [Git: inverse ignoring (.gitignore)](https://stackoverflow.com/questions/13398648/git-inverse-ignoring-gitignore) – Andreas Feb 15 '19 at 04:02

3 Answers3

7

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
  • 30,962
  • 25
  • 85
  • 135
vauhochzett
  • 2,732
  • 2
  • 17
  • 40
4

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

*
!/app/
!/app/*
phd
  • 82,685
  • 13
  • 120
  • 165
1

Albeit @phd's answer is correct. It won't work if you have other directories nested inside. This should be a more foolproof solution.

*
!/app/
!/app/**/*
Omar Omeiri
  • 1,506
  • 1
  • 17
  • 33