简体   繁体   English

Git中的Eclipse Java项目

[英]Eclipse Java Projects in Git

I am trying to figure out the best way to create a java project in GIT. 我试图找出在GIT中创建Java项目的最佳方法。 In particular I would like to create the git repository such that when I import from git in Eclipse, the project is automatically created correctly with all its .project settings intact and all other settings setup. 特别是我想创建git存储库,这样当我从Eclipse中的git导入时,项目会自动正确创建,其所有.project设置都完好无损,并且所有其他设置都已设置。 IE if I do a git clone javaEclipseProject in my workspace/ folder then do an import on that javaEclipseProject folder it will open up the project without having to use the new project wizard. IE如果我在我的工作区/文件夹中执行git clone javaEclipseProject然后在该javaEclipseProject文件夹上执行导入,它将打开项目而无需使用新项目向导。

Add the dot-files (.project, .classpath and the .settings directory) to the Git repository. 将点文件(.project,.classpath和.settings目录)添加到Git存储库。 That is what we do with the Git plugin itself. 这就是我们使用Git插件本身所做的事情。

I'm sure you could do that....but I know even in the company I work for, .project files are not portable from one machine to another. 我相信你能做到这一点......但我知道即使在我工作的公司里,.project文件也无法从一台机器移植到另一台机器。 If you get your project building in either Ant or Maven then check it in, Eclipse, Netbeans and/or IntelliJ will be able to check out the project and build their own .project files from your start. 如果您在Ant或Maven中构建项目,然后检查它,Eclipse,Netbeans和/或IntelliJ将能够检查项目并从一开始就构建自己的.project文件。

Moving on to the more....shall we say "religious" aspects of the problem, personally I like the way Maven or Ivy or "insert many other Ant++ build tools here" will go ahead and find any dependencies that you might not have already and download them for you. 转到更多....我们应该说问题的“宗教”方面,我个人喜欢Maven或Ivy的方式或“在这里插入许多其他Ant ++构建工具”将继续发现你可能没有的任何依赖已经并为您下载它们。 I'm sad to say, but in the times I've used them, Eclipse actually has the least easy to use Maven support though, I don't use IntelliJ, but the snobs.....I mean co-workers I have that do say integration is seamless, and Netbeans it just flawless for Maven. 我很伤心地说,但我用他们的时候,Eclipse的却有至少易于虽然使用Maven的支持,我不使用的IntelliJ,但势利小人.....我的意思是同事我那就是说集成是无缝的,Netbeans对Maven来说是完美的。

YMMV of course. YMMV当然。

What you could do is to create another branch called eclipse next to your master branch which stores your additional eclipse project files. 你可以做的是在你的主分支旁边创建另一个名为eclipse分支,它存储你额外的eclipse项目文件。 To do so, you basically need to: 为此,您基本上需要:

  1. Create a git repository 创建一个git存储库
  2. Stage your files, add a .gitignore with the content of anything from eclipse for eg this one , commit everything 暂存你的文件,添加一个带有eclipse内容的.gitignore ,例如这个 ,提交一切
  3. Create a new branch called eclipse 创建一个名为eclipse的新分支
  4. Alter your .gitignore file or clear it, so that it will track your additional files 更改.gitignore文件或清除它,以便它将跟踪您的其他文件
  5. In your project directory execute git config merge.ours.driver true 在项目目录中执行git config merge.ours.driver true
  6. Still on your eclipse branch, create the file .gitattributes and add this line: .gitignore merge=ours . 仍然在您的eclipse分支上,创建文件.gitattributes并添加以下行: .gitignore merge=ours This will make git always keep the eclipse's branch version of .gitignore when performing a merge. 这将使git在执行合并时始终保持eclipse的.gitignore分支版本。
  7. Stage your .project file its siblings from eclipse together with your newly created .gitattributes .project文件与eclipse中的兄弟姐妹以及新创建的.gitattributes一起.gitattributes
  8. After committing all these things your two branches are "in sync" with the difference that your eclipse branch additionally contains the project configuration files. 提交所有这些东西之后,你的两个分支“同步”,区别在于你的eclipse分支还包含项目配置文件。

Once you make changes to your source files and commited them to your master branch, you can pull these changes over to your eclispe branch by merging it with the --no-ff option. 一旦对源文件进行了更改并将其提交到主分支,就可以通过将它们与--no-ff选项合并,将这些更改提取到eclispe分支。 It is important that you never do a fast-forward merge into the eclipse branch when using this method! 重要的是,在使用此方法时,永远不要快速合并到eclipse分支中! Also never commit changes on your source files to your eclipse branch directly, always merge them into - this way you will never get merge conflicts and keep your life simple. 也永远不要直接将源文件的更改提交到eclipse分支,始终将它们合并到 - 这样您就不会遇到合并冲突并保持简单的生活。

I'm not sure if this existed at the time the question was asked, but eclipse now has a new plugin called EGit in which you can import projects from git, commit, push, pull, merge, etc right in eclipse. 我不确定问题被问到时是否存在,但eclipse现在有一个名为EGit的新插件,你可以在eclipse中从git,commit,push,pull,merge等导入项目。 I just discovered this recently and it's very useful. 我刚刚发现了这个,它非常有用。

If i'm not mistaken, EGit is now built into Eclipse Mars without you needing to add it manually. 如果我没弄错的话,EGit现在内置于Eclipse Mars中,无需手动添加它。 All of the git functions can be found by right clicking on a project and hovering over the team option . 通过右键单击项目并将鼠标悬停在团队选项上,可以找到所有git函数。 I use it alot wtih Bitbucket 我用它很多Bitbucket

You can find EGit here http://www.eclipse.org/egit/ 你可以在这里找到EGit http://www.eclipse.org/egit/

Eclipse Mars is on the home page http://www.eclipse.org/ Eclipse Mars位于主页http://www.eclipse.org/

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM