I'm trying to implement the workaround for the NuGet Package Restore Issues.
This involves ignoring the contents of all packages folders, at any level in the hierarchy. However, .targets files (typically in subfolders of packages folders) should not be ignored.
For example:
.gitignore YourProject/ YourProject.csproj packages/ repositories.config Microsoft.Bcl.Build.1.0.7/ lib/ foo.dll tools/ Microsoft.Bcl.Build.targets
Should include only files:
Windows, git version 1.8.1.msysgit.1.
I have read several answers on StackOverflow, checked the man page, and tried numerous variants without success.
This does not work:
packages/*
!*.targets
Nor this:
packages/*
!packages/**/*.targets
Nor this:
**/packages/*
!**/packages/**/*.targets
Update:
bin/
, must continue to work.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
#
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With