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

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

问题描述

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

在签出项目之前,我需要将 GitHub 工作目录 (c:users) 设置为我的 Eclipse 工作目录 (c:Projects) 吗?

我的工作目录现在是 c:usersprojectname.git因此,我尝试使用 eclipse 的导入"选项导入项目.当我尝试导入选择使用新项目向导"选项时,不会导入源代码,如果我选择作为常规项目导入"选项导入,则会导入源代码,但由 Eclipse 创建的项目不是 java项目.选择使用新项目向导"选项并使用向导创建新的 java 项目时,代码不应该自动导入吗?

解决方案

如 中所述:

<块引用>

在任何情况下(除非您创建裸"存储库,但此处未讨论),新存储库本质上是本地硬盘上的文件夹,其中包含工作目录"和元数据文件夹.
元数据文件夹是一个名为.git"的专用子文件夹,通常称为.git-folder".它包含实际的存储库(即提交、引用、日志等).

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

通常,如果要在 Eclipse 中使用这些文件,则必须以一种或另一种方式将它们导入 Eclipse 工作区.为此,最简单的方法是签入 .project 文件,导入现有项目"向导可以从中轻松创建项目.因此,在大多数情况下,包含 Eclipse 项目的存储库的结构看起来类似于以下内容:

另请参阅在 Github 中使用 EGit 部分.

<小时><块引用>

我的工作目录现在是 c:usersprojectname.git

您应该在 c:usersprojectname 中检出该存储库的内容(换句话说,您应该拥有的不仅仅是 .git).

<块引用>

然后我尝试使用 Eclipse 的导入"选项导入项目.
当我尝试导入选择使用新项目向导"选项时,未导入源代码.

这很正常.

<块引用>

如果我选择作为一般项目导入"选项导入,则会导入源代码,但由 Eclipse 创建的项目不是 Java 项目.

又正常了.

<块引用>

选择使用新项目向导"选项并使用向导创建新的java项目时,代码不应该自动导入吗?

不,那只会创建一个空项目.
如果该项目是在 c:usersprojectname 中创建的,则您可以在该项目中声明 eisting 源目录.
由于它定义在与 Git 存储库相同的工作目录中,因此该项目应该显示为版本化".

如果您的 GitHub 存储库对 .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:usersprojectname.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 heGitHubRepoName".

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:usersprojectname.git

You should have the content of that repo checked out in c:usersprojectname (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:usersprojectname, 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天全站免登陆