git ignore 的使用
.gitignore NuGet exclude packages/ include packages/repositories.config
回答1
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.
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 Studio recommends the following solutions:
# 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.io to generate .ignore file for your favorite project :-)
This is an example of a .gitignore file, which is used by Git to determine which files and directories should be ignored when tracking changes in a repository. In this example, the file contains a comment and a few ignore patterns specific to NuGet package management in Visual Studio.
-
The first pattern
*.nupkg
is used to ignore NuGet package files that typically have this extension. This is a common file extension for software packages in the .NET ecosystem, which are often managed through the NuGet package manager. -
The second pattern
**/packages/*
ignores thepackages
directory and its contents, which is typically where NuGet packages are installed by default. This is because when using package restore, it is not necessary to commit the packages to source control, since they can be downloaded automatically when needed. -
The third pattern
!**/packages/build/
is a negative pattern that "unignores" thebuild
subdirectory of thepackages
directory. This is because this directory is used as an MSBuild target, and should not be ignored. -
The fourth pattern
#!**/packages/repositories.config
is commented out using the#!
syntax. This is because it is not always necessary to ignore therepositories.config
file, which is used to specify package sources for NuGet. If this file is not ignored, it can be useful to track changes to the package sources used by a project. However, this is commented out because it is generally regenerated automatically when needed.
Difference between pattern packages and **/packages/*
In the context of a .gitignore file, packages
matches any folder or file named exactly "packages" in the root of the repository or in any subdirectory. It would ignore, for example, a folder named "packages" in the root, but not a folder named "sub/packages".
On the other hand, **/packages/*
is a glob pattern that matches any folder or file that is under a folder named "packages" in the repository. The **
prefix matches any number of subdirectories, so it would match, for example, a file at src/foo/packages/bar.txt
. It would not match a file at packages/bar.txt
because it is not inside a folder named "packages".
The difference is that the first pattern only matches files or folders with the exact name "packages" in the root of the repository or in a subdirectory. The second pattern matches any file or folder that is inside a folder named "packages", regardless of its location in the repository.
http://www.barretlee.com/blog/2015/09/06/set-gitignore-after-add-file/
需要注意的 **
:
- 如果一个 pattern 以
**
开头,如**/foo
,最后会匹配所有文件夹下的 foo 文件(夹); - 如果一个 pattern 以
/**
开头,如abc/**
,则表示匹配 abc 目录下的所有内容; - 如果一个 pattern 中间包含
**
,如a/**/b
,则会匹配a/b
、a/x/b
、a/x/y/b
以及所有类似的内容。
需要找个时间验证下
忽略指定文件夹下的指定文件
**/Properties/launchSettings.json Properties即使是子文件夹也能生效
如果ignore不生效的话,需要注意,有可能是文字后面的空格导致的。
bin
obj
这些忽略,后面一定不要多出空格
https://stackoverflow.com/questions/5533050/gitignore-exclude-folder-but-include-specific-subfolder
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2014-09-12 TeeChart缩放