如果使用 Maven,是否应该忽略 VCS 中 Eclipse 特定的文件?
我知道为什么不将 Eclipse/IDE 特定的文件提交到像 Git(我实际上正在使用的)这样的 VCS 中。这就是我使用 Maven 并让它为您生成这些文件并且不将它们置于版本控制之下的原因之一。
但我想知道,这些文件是否应该在 .gitignore 中被忽略,而 .gitignore 本身是在 VCS/Git 的控制下:
.classpath
.project
.settings/
target/
这样可以吗?
由于 .gitignore 文件本身变得特定于 IDE,因为忽略的文件是特定于 IDE 的,因此有哪些优点和缺点?有什么最佳实践吗?
I know why not to commit Eclipse/IDE-specific files into a VCS like Git (which I am actually using). That is one of the reasons I am using Maven and having it generating these files for you and not having them under version control.
But I wonder, if these files should be ignored in .gitignore which itself is under control of VCS/Git:
.classpath
.project
.settings/
target/
Is this okay?
What are the pros and cons since the .gitignore file itself becomes kind of IDE-specific as the files ignored there are IDE-spefific? Any best-practice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在我工作过的团队中,一般规则是不要签入 Maven 生成或获取的任何内容。由于 pom.xml 包含创建 .project、.classpath 和 .settings 文件所需的所有内容,因此我们不会将它们签入。
我的 .gitignore 始终包含 .classpath、.settings、.project 和 Maven 项目的目标。
编辑:正如我在下面的评论中提到的,这是另一个建议:如果您确实想避免在 .gitignore 中包含 Maven 或 IDE 特定条目,尝试编写你的 .gitignore 这样你就只列出你所做的事情想要签入。
With the team's I've worked on, the general rule has been that you don't check in anything that is generated by or obtained by Maven. Since the pom.xml contains everything you need to create the .project, .classpath, and .settings files, we don't check them in.
My .gitignore always contains .classpath, .settings, .project, and target for Maven projects.
Edit: As mentioned in my comment below, here is another suggestion: If you really want to avoid having Maven or IDE specific entries in your .gitignore, try writing your .gitignore so you list only what you DO want checked in.
我从以下文章中获取信息: https://help.github.com/articles/ ignoring-files
这表明您可以创建一个包含 .project 等的全局 gitignore 文件(建议在 ~/.gitignore_global 下)。由于该文件位于存储库之外,因此不会显示...
您注册它作为全局忽略使用以下命令创建文件:
或者,您可以在 .git/info/exlude 文件中创建每个存储库未跟踪的 gitignore 条目
I'm getting my information from the following article: https://help.github.com/articles/ignoring-files
That suggests that you can create a global gitignore file (suggest under ~/.gitignore_global) containing .project, etc. As the file is outside the repo, it won't show...
You register it as a global ignore file with the following command:
Alternatively, you can create a per-repo untracked gitignore entries in the .git/info/exlude file
我同意不将 IDE 文件置于版本控制之下,这有时会导致各种麻烦,正如您提到的,使用 Maven 会使这变得不必要,因为任何开发人员都可以简单地从 POM 导入项目并开始,
如果这些文件没有放入.gitignore 它们很容易被错误签入
,而且我没有发现在 .gitignore 中列出它们使其成为 IDE 特定的,您可以列出 eclipse、IntelliJ IDEA 和 Netbeans 的项目文件,所有这些都在同一个文件中.gitignore 如果您的团队成员混合使用不同的 IDE。随着时间的推移,您可能会积累一个模板 .gitignore,该模板会忽略团队中使用的所有 IDE 中的项目文件,以便在创建新存储库时使用。
如果您完全反对将这些文件放入项目 .gitignore 中,您可以将它们放入用户中.gitignore,但在我看来有点宽松,因为它取决于正确配置的各个开发机器,并且还需要维护这些机器以与任何新添加保持同步
编辑:我目前有一个等效的.hgignore,相同的概念不同的语法,我将其转换为 git 作为此类 .gitignore 文件的示例
I agree on not putting the IDE files under version control, this occasionally causes all sorts of pains, and as you mentioned using maven renders this unnecessary as any developer can simply import the project from the POM and get going
If these files are not put in the .gitignore they can easy be checked in by mistake
furthermore I do not find listing them in the .gitignore makes it IDE specific, you can list project files of eclipse, IntelliJ IDEA, and Netbeans, all in the same .gitignore if your team members use a mix of different IDEs. Over time you may accumulate a template .gitignore that ignores project files from all IDEs used in your team(s) to use whenever you create a new repository
If you are totally against putting these in the project .gitignore you can put them in the users .gitignore, but that in my mind is a bit looser as it depends on the individual development machines being configured correctly, and also these need to be maintained to be kept in sync with any new additions
Edit: I currently have an equivalent .hgignore, same concept different syntax, I converted it to git as an example of such a .gitignore file
通常 .project 和 .settings/ 应该进行版本控制并被忽略!
.classpath 和 target 不应该进行版本控制而是被忽略。
这是结帐实践的第一次初始启动。
也就是说,
好吗?
usually .project and .settings/ should likley be versioned and ignored!
.classpath and target should not be versioned but ignored.
This is a first inital boot-up on checkout-practice.
i.e.
ok?