当Git与Visual Studio解决方案(.sln)和项目一起使用时,我应该在.gitignore中包含哪些文件?


当前回答

使用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文件,然后按照您喜欢的方式合并保存的副本更改。

其他回答

我在c#项目中使用下面的.gitignore。在需要时添加其他模式。

[Oo]bj
[Bb]in
*.user
*.suo
*.[Cc]ache
*.bak
*.ncb
*.log 
*.DS_Store
[Tt]humbs.db 
_ReSharper.*
*.resharper
Ankh.NoLoad

某些项目可能需要添加*。显到他们的视觉工作室gitignore。输入输出文件。

这是因为新项目的一些Visual Studio项目属性被设置为生成清单文件。

参见“在Visual Studio中生成清单”

但是如果您已经生成了它们,并且它们是静态的(不会随着时间而改变),那么从.gitignore文件中删除它们是个好主意。

这就是Git for Windows这样的项目刚刚做的事情(适用于Git 2.24, 2019年第四季度)

参见Johannes Schindelin (dscho)的commit aac6ff7(2019年9月05日)。 (由Junio C Hamano—gitster—在commit 59438be中合并,2019年9月30日)

.gitignore: stop ignoring .manifest files On Windows, it is possible to embed additional metadata into an executable by linking in a "manifest", i.e. an XML document that describes capabilities and requirements (such as minimum or maximum Windows version). These XML documents are expected to be stored in .manifest files. At least some Visual Studio versions auto-generate .manifest files when none is specified explicitly, therefore we used to ask Git to ignore them. However, we do have a beautiful .manifest file now: compat/win32/git.manifest, so neither does Visual Studio auto-generate a manifest for us, nor do we want Git to ignore the .manifest files anymore.

如果您在解决方案中使用dbproj,则需要添加以下内容:

#Visual Studio DB Project
*.dbmdl
[Ss]ql/

来源: http://blogs.msdn.com/b/bahill/archive/2009/07/31/come-visit-revisit-the-beer-house-continuous-integration.aspx

我明白这是一个老问题,还在分享一个信息。在Visual Studio 2017中,只需右键单击解决方案文件,并选择将解决方案添加到源代码控制

这将向源文件夹中添加两个文件。

.gitattributes .gitignore

这是最简单的方法。

在Visual Studio中有一个快捷方式,因为它在2015年及以上版本支持Git开箱即用。对于新的解决方案(或一些没有.git文件夹的解决方案),使用解决方案资源管理器中的源代码控制功能:

右键单击解决方案并选择将解决方案添加到源代码控制…弹出菜单中的项目。

它会自动初始化.git存储库,将.gitignore和必要的东西添加到您的解决方案,甚至是.gitattributes文件(行结束符等)。

文本将出现在VS控制台:

A new Git repository has been created for you in C:\<path to your solution>
Commit ______ created locally in repository.

完成了!