将 Visual Studio 与 Git 结合使用时要忽略的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1677113/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:55:41  来源:igfitidea点击:

Files to ignore when using Visual Studio with Git

visual-studiogitversion-controldevelopment-environment

提问by Kelly S. French

I've installed Git to do some development using Visual Studio 2008. Most of the work will be new development but we do have some old projects from prior to VS2005 that I want to bring over into the new repository. There is an existing thread about general VS/Git integrationbut my question is limited to the .gitignore file and Visual Studio.

我已经安装了 Git 以使用 Visual Studio 2008 进行一些开发。大部分工作将是新的开发,但我们确实有一些 VS2005 之前的旧项目,我想将它们带入新的存储库。有一个关于一般VS/Git 集成的现有线程,但我的问题仅限于 .gitignore 文件和 Visual Studio。

My question has two parts:

我的问题有两个部分:

  • What entries should be included in the .gitignore file to cover the Visual Studio specific files like binaries, assemblies, debug files, etc? Some were covered in the thread mentioned above but is there a comprehensive set?

  • In what situations have you needed to exclude files globally, or for a single repository, or using the environment variable?

  • .gitignore 文件中应包含哪些条目以涵盖 Visual Studio 特定文件,如二进制文件、程序集、调试文件等?上面提到的线程中涵盖了一些内容,但是否有一个全面的集合?

  • 在什么情况下,您需要全局排除文件,或针对单个存储库,或使用环境变量?

I already know the HOW. Here is an excerpt from the Git user-manualon ignoring files.

我已经知道如何。以下是关于忽略文件的 Git用户手册的摘录。

If you wish the exclude patterns to affect only certain repositories (instead of every repository for a given project), you may instead put them in a file in your repository named .git/info/exclude, or in any file specified by the core.excludesfile configuration variable. Some git commands can also take exclude patterns directly on the command line. See gitignore(5)for the details.

如果您希望排除模式仅影响某些存储库(而不是给定项目的每个存储库),您可以将它们放在名为 .git/info/exclude 的存储库中的文件中,或者放在核心指定的任何文件中。 excludesfile 配置变量。一些 git 命令也可以直接在命令行上采用排除模式。有关详细信息,请参阅gitignore(5)

采纳答案by user195595

In GitExtensions the default .gitignore is this. It can be a bit shorted by removing most individual file extensions and only exclude the directories they are in.

在 GitExtensions 中,默认的 .gitignore 是这个。通过删除大多数单独的文件扩展名并只排除它们所在的目录,它可能会有点短。

*.obj
*.exe
*.exp
*.pdb
*.dll
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
*.zip
[Dd]ebug*/
*.lib
*.sbr
Thumbs.db
[Ll]ib/
[Rr]elease*/
[Tt]est[Rr]esults/
_UpgradeReport_Files/
_ReSharper.*/

回答by Michael Hackner

You should ignore:

你应该忽略:

  • the bindirectory
  • the objdirectory
  • *.suo
  • *.user
  • bin目录
  • obj目录
  • *.suo
  • *.user