10

I tried this .gitignore file:

 *
 !mydirectory.ext
 !.gitignore

But it's not working, everything except the gitignore is ignored.

Also tried:

 !\mydirectory\.ext

The directory needs an extension because its a plugin for an app.

Any workarounds?

2 Answers2

10

ref

*
!/mydirectory.ext/
!/mydirectory.ext/*
!/mydirectory/.ext/
!/mydirectory/.ext/*
!.gitignore

or

*
# ignore all 
!/.*/
# but not directories which names starting with a dot
!/.*/*
# and all its contents
/.*/*/
# but ignore other directories (which names not starting with a dot)
# which results also not tracking its files underneath
!/.*/.*/
# but not to subdirectories (which names starts with a dot)
!/.*/.*/*
# and its contents


!/*.*/
# don't ignore directories which names has a dot in it
!/*.*/*
# and its contents
# extend it like with /.*/ 
!.gitignore

and so on

Community
  • 1
  • 1
mflatischler
  • 318
  • 1
  • 9
2

Those kind of whitelist are not easy possible in git.

Once you ignore a directory git won't look inside of it and hence won't check for exceptions inside this directory.

The only way to come around this is with long include/exclude cascades, which are really ugly.

The best way is to think again about your problem and try to solve it without such general exceptions, for example by explicitly ignoring everything you are sure you do not want.

michas
  • 25,361
  • 15
  • 76
  • 121