.gitignore NuGet packages folder at any level but include .targets file at any level
There is no 'good' way to do it (see manpage as a proof), however there is a hack around it.
Main issue with ignoring packages/
of the bat is that git does not even check it's subdirectories due to directory being ignored.
Solution here - you will have to have 2 gitignore files. One regular, and one inside the packages directory that looks like this:
# ignore all files*# do not ignore directories!*/# do not ignore targets!*.targets# do not ignore gitignore!*.gitignore
New example:
$ mkdir foo$ cd foo/$ mkdir foo$ mkdir foo/bar$ mkdir foo/bar/baz$ touch foo/.foo$ touch foo/bar/.foo$ touch foo/bar/baz/.foo$ touch regular.txt$ touch foo/ignored.txt$ touch foo/bar/baz/ignored-2.txt$ cat foo/.gitignore*!*/!*.foo!regular.txt!.gitignore$ git add . && git status# On branch master## Initial commit## Changes to be committed:# (use "git rm --cached <file>..." to unstage)## new file: foo/.foo# new file: foo/bar/.foo# new file: foo/bar/baz/.foo# new file: regular.txt#
The precedence of ignored paths is important, I take it.
I fixed this problem by specifying first what to keep then to ignore the rest of packages's content.
In .gitignore
file make sure you should have:
!packages/repositories.configpackages/
See https://github.com/danyandresh/Research/commit/65291219a1c1fbcdb2216c686767e8c46451baa1
Please note my .gitignore
file is a simple copy of Visual studio ignore list as found on github