我正在尝试为 NuGet Package Restore Issues 实现解决方法.
这涉及忽略层次结构中任何级别的所有包文件夹的内容。但是,不应忽略 .targets 文件(通常位于包文件夹的子文件夹中)。
例如:
.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:
- .gitignore
- YourProject.csproj
- Microsoft.Bcl.Build.targets
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
也不是这个:
packages/*
!packages/**/*.targets
也不是这个:
**/packages/*
!**/packages/**/*.targets
更新:
- 无论包文件夹在层次结构中的什么位置,这都需要起作用。
- 需要忽略包、子文件夹、子子文件夹等下的文件。
- 其他 .gitignore 行,如
bin/
,必须继续工作。
最佳答案
没有“好的”方法来做到这一点(请参阅 manpage 作为证明),但是有一个破解方法。
忽略 bat 的 packages/
的主要问题是由于目录被忽略,git 甚至不检查它的子目录。
这里的解决方案 - 你必须有 2 个 gitignore 文件。一个是常规的,一个在 packages 目录中,如下所示:
# ignore all files
*
# do not ignore directories
!*/
# do not ignore targets
!*.targets
# do not ignore gitignore
!*.gitignore
新例子:
$ 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
#
关于windows - .gitignore 任何级别的 NuGet 包文件夹,但包括任何级别的 .targets 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17153152/