为什么在Git中忽略特定于IDE的项目文件

为什么在Git中忽略特定于IDE的项目文件

本文介绍了为什么在Git中忽略特定于IDE的项目文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到Github上发布的许多项目都有一个 .gitignore 文件,它明确排除了与IDE相关的控制文件。这些控制文件广泛用于定义项目及其依赖项。对于.NET,这些可以是 .sln .project



我想问一下,为什么这种做法被广泛应用或被认为是一种好的做法,考虑到我一致认为实现IDE中立性(不要将开发人员绑定到特定的IDE)是一个很好的原则。 / p>

相反,这些控制文件通常会在多个配置中指定项目依赖项,配置或编译变量(这是 .csproj files)。



我已经看到大量的忽略Eclipse文件的开源项目,但是到目前为止我还没有设置建立一个没有项目文件的开发环境(即使我从现有代码创建项目,或者创建一个新项目并导入代码,我总会遇到大量的编译错误)。



如果项目文件存在于存储库中,设置开发环境很简单h下载代码,导入项目并且编译源代码,但它显然会将开发人员绑定到特定的IDE(这并不好笑)。

标准化或迁移项目文件超出了问题的范围。

因此,从外部贡献者的角度来看,如何构建项目的工作和编译项目环境其中他从Github下载了源代码? (在克隆所有子模块之后,如果需要的话)



只需选择一个示例项目,我想导入到Eclipse中,分析并略微修改, 。


为您的IDE生成项目文件是小菜一碟。这使得没有必要检查它们到版本控制中,因为它们可以被认为是构建工件。



另外在一个混合团队中,不同的人使用不同的IDE,当有人更新了Eclipse项目文件,使用IntelliJ的人突然也需要更新他的项目文件,因为他现在正在编译问题。而使用生成这些文件的构建系统可以确保它们始终保持最新状态。当你将M2Eclipse插件添加到Eclipse或使用IntelliJ时,甚至可以在没有用户交互的情况下使用Maven。

因此,我总是主张将项目文件添加到 .gitignore ...


I have seen that a number of projects posted on Github feature a .gitignore file explicitly excluding control files related to the IDE. These control files are widely used to define the project and its dependencies. These can be .sln for .NET or .project for Eclipse.

I want to ask why is this practice widely applied or considered a good practice, considering that I agree that achieving IDE-neutrality (don't bind developers to a specific IDE) is a good principle, in general.

On the contrary, these control files often dictate project dependencies, configuration or compilation variables in multiple configurations (this is the case of the .csproj files for example).

I have seen a large number of open source projects ignoring Eclipse files, however it has been impossible to me so far to set up a development environment without the project files (even if I create a project from existing code, or create a new project and import the code, I always get plenties of compilation errors).

If the project files were present in repositories it would be vry simple to set up a development environment with "download the code, import the project and voilà compile the source" but it would obviously bind developer to a specific IDE (and that's not funny).

Standardizing or migrating project files is out of the scope of the question.

So, from an external contributor's point of view, how does one build up a working and compiling project environment for a project of which he downloaded the source code from Github? (after cloning all submodules, if needed)

Just to pick one example project I would like to import into Eclipse, analyse and slightly modify, here it is.

解决方案

With quite a lot of build-systems in the Java world (Maven, Gradle, SBT, etc). It is a piece of cake to generate the project files for your IDE. This makes it unnecessary to check them into version control, as they can be considered a build artifact.

Furthermore in a mixed team, where different people use different IDE's, when somebody updates the Eclipse project files, the guy using IntelliJ suddenly also needs to update his project files, as he now gets compilation problems. Whereas using a build system that generates these files, ensures that they're always up-to-date. Using Maven for instance this is even done without user interaction when you add the M2Eclipse plugin to Eclipse or use IntelliJ.

So I always advocate to add the project files to .gitignore...

这篇关于为什么在Git中忽略特定于IDE的项目文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 05:46