将GitHub项目导入Eclipse [英] Importing a GitHub project into Eclipse

查看:209
本文介绍了将GitHub项目导入Eclipse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我导入了一个GitHub项目,但是如何在Eclipse项目工作区中设置项目?



我需要设置GitHub工作目录(c: \users)到我的Eclipse工作目录(c:\Projects)之前检出项目?





已编辑:



我的工作目录现在是c:\users\projectname\.git
那么我尝试使用eclipseimport选项导入项目。当我尝试导入选择使用新的项目向导选项时,不导入源代码,如果我导入选择导入为一般项目选项,则导入源代码,但由Eclipse创建的创建的项目不是java项目。当选择使用新项目向导选项并使用向导创建新的Java项目时,应该自动导入代码?



解决方案

在:


无论如何(除非你创建一个裸存储库,但这里没有讨论),新的存储库本质上是本地硬盘上包含工作目录和元数据文件夹的文件夹。

元数据文件夹是一个专用的子文件夹,名为 .git ,通常称为 .git-folder 。它包含实际的存储库(即提交,引用,日志等)。



元数据文件夹对Git客户端是完全透明的,而工作目录是用于将当前检出的存储库内容公开为工具和编辑器的文件。



通常,如果这些文件要在Eclipse中使用,则必须将其导入到Eclipse以某种方式工作。为了做到这一点,最简单的方法是检入.project文件,导入现有项目向导可以轻松创建项目。因此,在大多数情况下,包含Eclipse项目的存储库的结构将类似于以下内容:


另请参见使用EGit与Github 部分。







我的工作目录现在是 c:\users\projectname\.git


您应该在 c:\users\projectname中检出该repo的内容(换句话说,你应该不仅仅是 .git )。


所以我尝试使用eclipseimport选项导入项目。

当我尝试导入选择使用新的项目向导选项时,源代码没有导入。


这是正常的。


如果我导入选择选择离子导入为一般项目源代码是导入的,但由Eclipse创建的创建的项目不是一个java项目。


再次正常。


选项使用新项目向导并使用向导创建一个新的Java项目,不应该自动导入代码?


不,这只会创建一个空项目。

如果该项目是在 c:\users\projectname 中创建的,那么您可以声明在该项目中列出源目录。

由于它在与Git repo相同的工作目录中定义,所以该项目应该显示为版本化。



您也可以使用导入现有项目选项,如果您的GitHub repo版本为 .project .classpath 文件,但这可能不是这种情况。


I've imported a GitHub project but how do I setup the project in my Eclipse project workspace?

Do I need to set the GitHub working directory(c:\users) to my Eclipse working directory(c:\Projects) prior to checking out the project ?

Edited :

My working directory is now c:\users\projectname\.git So then I try to import the project using the eclipse "import" option. When I try to import selecting the option "Use the new projects wizard" the source code is not imported, if I import selecting the option "Import as general project" the source code is imported but the created project created by Eclipse is not a java project. When selecting the option "Use the new projects wizard" and creating a new java project using the wizard should'nt the code be automatically imported ?

解决方案

As mentioned in Alain Beauvois's answer, and now (Q4 2013) better explained in

Copy the URL from GitHub and select in Eclipse from the menu the

File → Import → Git → Projects from Git


If the Git repo isn't cloned yet:

In> order to checkout a remote project, you will have to clone its repository first.
Open the Eclipse Import wizard (e.g. File => Import), select Git => Projects from Git and click Next.
Select "URI" and click Next.
Now you will have to enter the repository’s location and connection data. Entering the URI will automatically fill some fields. Complete any other required fields and hit Next. If you use GitHub, you can copy the URI from the web page.

Select all branches you wish to clone and hit Next again.

Hit the Clone… button to open another wizard for cloning Git repositories.


Original answer (July 2011)

First, if your "Working Directory" is C:\Users, that is odd, since it would mean you have cloned the GitHub repo directly within C:\Users (i.e. you have a .git directory in C:\Users)

Usually, you would clone a GitHub repo in "any directory of your choice\theGitHubRepoName".

As described in the EGit user Manual page:

In any case (unless you create a "bare" Repository, but that's not discussed here), the new Repository is essentially a folder on the local hard disk which contains the "working directory" and the metadata folder.
The metadata folder is a dedicated child folder named ".git" and often referred to as ".git-folder". It contains the actual repository (i.e. the Commits, the References, the logs and such).

The metadata folder is totally transparent to the Git client, while the working directory is used to expose the currently checked out Repository content as files for tools and editors.

Typically, if these files are to be used in Eclipse, they must be imported into the Eclipse workspace in one way or another. In order to do so, the easiest way would be to check in .project files from which the "Import Existing Projects" wizard can create the projects easily. Thus in most cases, the structure of a Repository containing Eclipse projects would look similar to something like this:

See also the Using EGit with Github section.


My working directory is now c:\users\projectname\.git

You should have the content of that repo checked out in c:\users\projectname (in other words, you should have more than just the .git).

So then I try to import the project using the eclipse "import" option.
When I try to import selecting the option "Use the new projects wizard", the source code is not imported.

That is normal.

If I import selecting the option "Import as general project" the source code is imported but the created project created by Eclipse is not a java project.

Again normal.

When selecting the option "Use the new projects wizard" and creating a new java project using the wizard should'nt the code be automatically imported ?

No, that would only create an empty project.
If that project is created in c:\users\projectname, you can then declare the eisting source directory in that project.
Since it is defined in the same working directory than the Git repo, that project should then appear as "versioned".

You could also use the "Import existing project" option, if your GitHub repo had versioned the .project and .classpath file, but that may not be the case here.

这篇关于将GitHub项目导入Eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆