12

我正在尝试实施NuGet Package Restore Issues的解决方法。

这涉及忽略层次结构中任何级别的所有包文件夹的内容。但是,不应忽略 .targets 文件(通常位于包文件夹的子文件夹中)。

例如:

.gitignore
你的项目/
  你的项目.csproj
  包/
    存储库.config
    Microsoft.Bcl.Build.1.0.7/
      库/
        foo.dll
      工具/
        Microsoft.Bcl.Build.targets

应仅包括文件:

  • .gitignore
  • 你的项目.csproj
  • Microsoft.Bcl.Build.targets

Windows,git 版本 1.8.1.msysgit.1。

我已经阅读了 StackOverflow 上的几个答案,检查了手册页,并尝试了许多变体但没有成功。

这不起作用:

packages/*
!*.targets

也不是这个:

packages/*
!packages/**/*.targets

也不是这个:

**/packages/*
!**/packages/**/*.targets

更新:

  • 无论包文件夹在层次结构中的位置,这都需要工作。
  • 它需要忽略包、子文件夹、子子文件夹等下的文件。
  • 其他 .gitignore 行,如bin/,必须继续工作。
4

2 回答 2

8

没有“好”的方法来做到这一点(参见手册页作为证明),但是有一个 hack 围绕它。

忽略 bat 的主要问题packages/是由于目录被忽略,git 甚至不检查它的子目录。

解决方案在这里 - 你必须有 2 个 gitignore 文件。一个常规的,一个在包目录中,如下所示:

# 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
#
于 2013-06-17T19:03:17.540 回答
1

我认为忽略路径的优先级很重要。

我通过首先指定要保留的内容然后忽略其余包的内容来解决此问题。

.gitignore文件中确保您应该拥有:

!packages/repositories.config
packages/

https://github.com/danyandresh/Research/commit/65291219a1c1fbcdb2216c686767e8c46451baa1

请注意,我的文件是在 github 上找到.gitignore的 Visual Studio 忽略列表的简单副本

于 2014-01-10T13:09:30.493 回答