git 将 .gitignore 添加到 Repo 的最佳实践

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

Best Practice for Adding .gitignore to Repo

gitgitignore

提问by E-rich

What is the best practice regarding the .gitignorefile with Git; should it be excluded from the repository or included? If it's conditional, what are the conditions for each circumstance?

关于Git的.gitignore文件的最佳实践是什么?它应该从存储库中排除还是包含在内?如果是有条件的,那么每种情况的条件是什么?

回答by meagar

They should almost always be included, as their purpose is to ignore "output" files (compiled binaries, log files) which are going to be generated by anybody working with a clone of your project. They're meant to be version-controlled and included with the repository.

它们几乎总是被包含在内,因为它们的目的是忽略任何人使用您的项目的克隆生成的“输出”文件(编译后的二进制文件、日志文件)。它们旨在受版本控制并包含在存储库中。

You should not use .gitignorefiles within the repository to ignore files that only appear for you, such as editor-specific swap files. You should be placing those rules in a global .gitignorefileso that they apply to all repositories, or in .git/info/excludes.

您不应使用.gitignore存储库中的文件来忽略仅为您显示的文件,例如特定于编辑器的交换文件。您应该将这些规则放在一个全局.gitignore文件中,以便它们适用于所有存储库,或者放在.git/info/excludes.