1

Because I'm using microsoft nuget, I want to ignore all the package directories in my projects (there are a huge number of these and those files are all temporary). Unfortunately, in the JavaScript library I also have in the same repository, I need the package directory. So, I have in my .gitignore

...
package
...

But, in my directory

/JavaScript/package/importantfiles

I want to not ignore this file.

How can I let all "package" get ignored, but in the directory /JavaScript/... I want package to be included in source control?

Peter Kellner
  • 14,748
  • 25
  • 102
  • 188

1 Answers1

3

Don't forget that:

It is not possible to re-include a file if a parent directory of that file is excluded (*)
(*: unless certain conditions are met in git 2.8+, see below)

It means that you need to ignore package folder files in order to un-ignore one of those files:

package/*
!importantFile

Note that with git 2.8.x/2.9 (mid 2016?), it might be possible to re-include a file if a parent directory of that file is excluded if there is no wildcard in the path re-included.

Nguyễn Thái Ngọc Duy (pclouds) is trying to add this feature:

So in your case, this would work:

/JavaScript/package
!/JavaScript/package/importantfiles
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250