将 .gitignore 添加到存储库的最佳实践
关于 Git 的 .gitignore 文件的最佳实践是什么?应该将其从存储库中排除还是包含在内?如果是有条件的,每种情况的条件是什么?
What is the best practice regarding the .gitignore file with Git; should it be excluded from the repository or included? If it's conditional, what are the conditions for each circumstance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们几乎总是应该被包含在内,因为它们的目的是忽略“输出”文件(编译的二进制文件、日志文件),这些文件将由任何使用项目克隆的人生成。它们应该受到版本控制并包含在存储库中。
您不应使用存储库中的 .gitignore 文件来忽略只为您显示的文件,例如特定于编辑器的交换文件。您应该将这些规则放在 全局
.gitignore
文件 中,以便它们适用于所有存储库,或在.git/info/excludes
中。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
.gitignore
files 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.gitignore
file so that they apply to all repositories, or in.git/info/excludes
.