git .gitignore NuGet 排除包/包含包/repositories.config
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10779343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.gitignore NuGet exclude packages/ include packages/repositories.config
提问by Dipesh
I'm trying to create a .gitignore for a Visual Studio project that uses NuGet. It currently contains:
我正在尝试为使用 NuGet 的 Visual Studio 项目创建一个 .gitignore。它目前包含:
\packages/*
!packages/repositories.config
This does not ignore anything in the folder. Everything gets staged on an add. I have also tried:
这不会忽略文件夹中的任何内容。一切都在添加上上演。我也试过:
packages/
!packages/repositories.config
This ignores everything in the packages folder and does not include the packages/repositories.config.
这将忽略包文件夹中的所有内容,并且不包括包/repositories.config。
What am I doing wrong?
我究竟做错了什么?
回答by manojlds
/packages/
!packages/repositories.config
You can also add a .gitignore
in the packages folder:
您还可以.gitignore
在包文件夹中添加一个:
*
!repositories.config
!.gitignore
回答by Ali Reza Dehdar
I faced the same issue.
我遇到了同样的问题。
None of the above solutions worked for me. And I think it's a poor solution to maintain multiple .ignore files.
以上解决方案都不适合我。而且我认为维护多个 .ignore 文件是一个糟糕的解决方案。
This is how I solved it.
我就是这样解决的。
**/packages/*
!**/packages/repositories.config
Combining two asterisks will match any string of folders. I thought leaving out asterisks would have the same effect, but apparently I (we) were wrong, as it doesn't seem to work.
组合两个星号将匹配任何文件夹字符串。我认为省略星号会产生同样的效果,但显然我(我们)错了,因为它似乎不起作用。
The official .gitignore template for Visual Studiorecommends the following solutions:
Visual Studio的官方.gitignore 模板推荐了以下解决方案:
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
EDIT: You can use https://www.gitignore.ioto generate .ignore file for your favorite project :-)
编辑:您可以使用https://www.gitignore.io为您喜欢的项目生成 .ignore 文件:-)
回答by Grant Birchmeier
This works for me.
这对我有用。
#NuGet
packages
!packages/repositories.config
(Same as @manojlds's answerexcept removed the star in the first line. That didn't work for me.)
(与@manojlds 的答案相同,只是删除了第一行中的星号。这对我不起作用。)
回答by ygoe
I found this simple pattern works.
我发现这个简单的模式有效。
/packages/*/
It should ignore all directories in the root packages directory, but include all files there. Not sure what other files than repositories.config might appear in there or whether they should be included in the repository.
它应该忽略根包目录中的所有目录,但包含那里的所有文件。不确定除了 repositories.config 之外还有哪些其他文件可能会出现在那里,或者它们是否应该包含在存储库中。
See also .gitignore Syntax: bin vs bin/ vs. bin/* vs. bin/**