简体   繁体   中英

Eclipse setup for git project

There are quite a few questions on this topic, but there are no satisfactory answers unitl now, eg this .

I'm using Eclipse Kepler (20130529-2219), with ME2 (1.4.0.20130601-0317) and Eclipse Git Team Provider (Java implementation of GIT 3.0.0.201306040240-rc3). So I started with great expectations after reading how great git is.

Firstly, I opened an existing project and removed all the .svn rubbish and commited it to a local git repository. Perfect - now it is time to push the files to a remote repository. After having some problems creating the known_hosts file on Windows the push was successful.

Now the problems started: I wanted to pull changes for the repository, but "... not configured for pull". OK, here it was discussed that this is a common issue, and you have to delete the project and then reimport it from a remote server to allow pulling.

Hence, I set up everything again and pulled the project. Until now I was always told that .project files should not be commit to version control, therefore I didn't include them. The "import -> import from git -> local"-menu does not recognize the files in the repo as a Java project. I can therefore only import the project as a general project or use the project wizzard and set up a new Maven project, which is stupid because all information already exists in the POM.xml. If I do a plain project import, Eclipse does not know that it is a Java or Maven project and throws tonnes of errors.

Question (skip detailed problem): Is there some less awkward way to import a Maven and Java project from a remote git repo when no .project file exists?

Easiest solution: do include the .project (as in this answer ) in your git repo.

And do include also the .classpath , since you now can reference relative paths in it, instead of absolute path: see " .classpath and .project - check into version control or not? "

I found an alternative to keep .project file out of Git version control. As you said the pom.xml file should be enough for IDEs to figure out that a maven project it´s in place (and it is).

Let's say you have pushed your project into Git (without .project file) and now you want to import that project into Eclipse.

  1. Make sure you have the Git repo added into Git perspective
  2. Go to J2EE Perspective and double click on an empty space on Navigation View. Import -> Existing Maven Projects
  3. Browse to your Git repo location and voila! Eclipse should catch all pom.xml files and determinate they are independent Maven projects

In my case this worked to pull multiple projects located at one same Git repo, each of them only storing pom.xml file (and no .project at all)

I found useful video for this answer: git configuration in eclipse with commit/fetch

  1. Configuration of git in eclipse,
  2. pushing eclipse project to github,
  3. fetching github project to eclipse,
  4. working with branch ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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