当Git与Visual Studio解决方案(.sln)和项目一起使用时,我应该在.gitignore中包含哪些文件?
当前回答
对于那些对微软认为应该包含在gitignore中感兴趣的人,这里是Visual Studio 2013 RTM在创建一个新的Git-Repository时自动生成的默认gitignore:
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/
# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
!packages/*/build/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
#LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
# =========================
# Windows detritus
# =========================
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac desktop service store files
.DS_Store
参见:在MSDN上添加默认的.gitignore文件
其他回答
我在c#项目中使用下面的.gitignore。在需要时添加其他模式。
[Oo]bj
[Bb]in
*.user
*.suo
*.[Cc]ache
*.bak
*.ncb
*.log
*.DS_Store
[Tt]humbs.db
_ReSharper.*
*.resharper
Ankh.NoLoad
使用Visual Studio添加.gitignore
打开Visual Studio和需要忽略文件的解决方案。从顶部菜单选择Git > Settings。
上面将打开Visual Studio的选项,选择源代码控制> Git全局设置。从左侧列表中选择Git Repository Settings,然后单击“忽略文件”的“添加”按钮。
上面的代码将添加(并提交)一个.gitignore文件,其中包含典型Visual Studio设置中忽略的所有适当文件。
https://elanderson.net/2020/10/add-git-ignore-to-an-existing-visual-studio-solution-new-git-experience/
注意,如果你的repo根目录中已经有一个.gitignore文件,“添加”按钮将显示“编辑”,按下该按钮将只是打开文件而不更新它,这不是很有帮助。在这种情况下,您可以首先重命名您的.gitignore文件,单击Add按钮,取消新的.gitignore文件,然后按照您喜欢的方式合并保存的副本更改。
参见官方GitHub的“有用的。gitignore模板集合”。
Visual Studio的.gitignore可以在这里找到: https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
您可以通过转到团队资源管理器中的设置视图,然后选择存储库设置来创建或编辑您的.gitignore文件。选择编辑你的。gitignore。
它会自动创建过滤器,忽略所有VS特定的构建目录等。
更多信息请看这里。
这是我最近在做的一个项目的。gitignore的摘录。我提取了我认为与Visual Studio相关的内容,包括编译输出;这是一个跨平台的项目,所以对于其他构建系统产生的文件有各种其他的忽略规则,我不能保证我准确地将它们分开。
*.dll
*.exe
*.exp
*.ilk
*.lib
*.ncb
*.log
*.pdb
*.vcproj.*.user
[Dd]ebug
[Rr]elease
也许这个问题应该是Community Wiki,这样我们就可以一起编辑一个带有注释的主列表,说明对于哪种类型的项目哪些文件应该被忽略?
推荐文章
- 为什么调用git分支——unset-upstream来修复?
- Windows git“警告:LF将被CRLF取代”,这是警告尾巴向后吗?
- git中的哈希冲突
- git可以自动在空格和制表符之间切换吗?
- Git暂存文件列表
- 如何将git配置存储为存储库的一部分?
- 如何修改GitHub拉请求?
- 如何在没有任何错误或警告的情况下找到构建失败的原因
- 如何在Github和本地删除最后n次提交?
- Visual Studio弹出提示:“操作无法完成”
- 我如何调试git/git-shell相关的问题?
- 为什么我在我的Excel插件中得到“无法在证书存储中找到清单签名证书”?
- 错误:无法使用rebase进行拉取:您有未分阶段的更改
- Git隐藏未缓存:如何把所有未分期的变化?
- 真实的恶魔