git Eclipse + EGit:将项目克隆到工作区

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6396349/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:12:25  来源:igfitidea点击:

Eclipse + EGit: clone project into workspace

eclipsegitgithubegit

提问by Manuel Mauky

I'm a little confused about how EGit workes.

我对 EGit 的工作方式有点困惑。

I have an existing git repository on Github and want to clone it into my workspace. My goal is to have the local repository directly stored inside my workspace-folder but I don't get it working with EGit.

我在 Github 上有一个现有的 git 存储库,想将其克隆到我的工作区中。我的目标是将本地存储库直接存储在我的工作区文件夹中,但我无法将其与 EGit 一起使用。

When I want to clone the github repo with EGit, I have to choose a directory as destination. The suggested directory is in my homedir (not in my workspace). When I choose this directory I can see the project in Eclipse but it is not stored in my workspace-folder. Instead it is stored in my home dir.

当我想用 EGit 克隆 github repo 时,我必须选择一个目录作为目标。建议的目录在我的 homedir 中(不在我的工作区中)。当我选择这个目录时,我可以在 Eclipse 中看到该项目,但它没有存储在我的工作区文件夹中。相反,它存储在我的主目录中。

When I choose a directory directly inside my workspace, later when it comes to import the project it says that there is already a directory with this name.

当我直接在我的工作区中选择一个目录时,稍后在导入项目时,它说已经有一个具有此名称的目录。

I don't know how to solve this. I thought this would be a common scenario. In the past I have used hgEclipse (Mercurial) and it was working exactly the way I thought it should be so I'm confused EGit doesn't. Maybe I misunderstood something.

我不知道如何解决这个问题。我认为这将是一个常见的场景。在过去,我使用过 hgEclipse (Mercurial),它的工作方式与我认为的完全一样,所以我很困惑 EGit 没有。也许我误解了一些东西。

Probably this is important to know: In the github repository there are no .project or .settings files from eclipse. I have them on my .gitignore and so in the import-dialog I have to choose "Import as General Project" and not "Import Existing Projects". But I think this shouldn't matter?

了解这一点可能很重要:在 github 存储库中,没有来自 eclipse 的 .project 或 .settings 文件。我将它们放在我的 .gitignore 中,因此在导入对话框中我必须选择“作为常规项目导入”而不是“导入现有项目”。但我认为这应该无关紧要吗?

I hope someone can help me or explain me why the EGit plugin doesn't clone the repository directly into the workspace by default.

我希望有人可以帮助我或解释为什么 EGit 插件默认情况下不会将存储库直接克隆到工作区中。

My Eclipseversion is 3.6, I have installed EGit over the markedplace.

我的 Eclipse 版本是 3.6,我已经在标记的地方安装了 EGit。

采纳答案by VonC

As mentioned in this EGit tutorial, the destination directory you mention when importing (cloning) a Git repo is any directory you want, in which the .gitwill be created:

如本EGit 教程中所述,您在导入(克隆)Git 存储库时提到的目标目录是您想要的任何目录,将在其中.git创建:

Import Git Repository

导入 Git 存储库

You don't have to select the workspace itself (at least, you should select the workspace/myprojectsubdirectory, in order to not make the allEclipse workspace a Git repo.

您不必选择工作区本身(至少,您应该选择workspace/myproject子目录,以免使所有Eclipse 工作区成为 Git 存储库。

And you can select any other directory outsidethe workspace: the Eclipse workspace should only contain meta-data about Eclipse projects and settings.
When declaring a new project, you will be able to select the project directory, making that directory the parent for .classpathand .project.
Your workspace will list that new project, even though it lives outside the workspace.

并且您可以选择工作区之外的任何其他目录:Eclipse 工作区应该只包含有关 Eclipse 项目和设置的元数据。
声明新项目时,您将能够选择项目目录,使该目录成为.classpath和的父目录.project
您的工作区将列出该新项目,即使它位于工作区之外。

回答by Luís de Sousa

To import a project from GitHub you should use the Import Git Repository as New Project dialogue (right click-> Import-> Git-> Git Repository as New Project). This way you can select the destination of the clone repository, including the Workspace.

要从 GitHub 导入项目,您应该使用 Import Git Repository as New Project 对话框(右键单击-> Import-> Git-> Git Repository as New Project)。通过这种方式,您可以选择克隆存储库的目的地,包括工作区。

回答by Vinod Reddy

If you want to edit the sources in the IDE and also want the changes to be reflected in the Git repository, delete the original source file in the project and link the source file in the git repo to the project. That way, you can directly make changes to the git repo and you can commit them when needed. Be careful not to delete the files when deleting the project in the IDE though.

如果您想在 IDE 中编辑源代码并希望将更改反映在 Git 存储库中,请删除项目中的原始源文件并将 git 存储库中的源文件链接到项目。这样,您可以直接对 git repo 进行更改,并且可以在需要时提交它们。在 IDE 中删除项目时注意不要删除文件。

回答by Krzysztof

Steps to have git project in workspace (with egit):

在工作区中创建 git 项目的步骤(使用 egit):

  1. On GIT perspective choose "Clone a Git Repository and add it to this view"
  2. As a destination choose folder inside a workspace (for example ".../workspace/myproject")
  3. Wait until cloned
  4. File -> New -> Project
  5. General -> project
  6. As a project name type name of a folder in workspace where project has been cloned (for example "myproject")
  1. 在 GIT 透视图中选择“克隆 Git 存储库并将其添加到此视图”
  2. 作为目的地选择工作区内的文件夹(例如“.../workspace/myproject”)
  3. 等到克隆
  4. 文件 -> 新建 -> 项目
  5. 一般 -> 项目
  6. 作为项目名称在已克隆项目的工作区中的文件夹的类型名称(例如“myproject”)

回答by John Tang Boyland

In the "Configure Local Storage Location" dialog, choose .../workspace/projectname.

在“配置本地存储位置”对话框中,选择 .../workspace/projectname。

Then in the next dialog, we get the wizard selection menu. Normally you should select "Import existing project". (But see below).

然后在下一个对话框中,我们得到向导选择菜单。通常您应该选择“导入现有项目”。(但见下文)。

Finally, there is the "Import Projects" dialog. For various unexplained reasons, sometimes this dialog is empty and won't let you finish. In that case, you need to cancel, and then outside of Eclipse completely delete the working directory that was cloned into, and then start again.

最后,还有“导入项目”对话框。由于各种无法解释的原因,有时这个对话框是空的,不会让你完成。在这种情况下,您需要取消,然后在 Eclipse 之外完全删除克隆到的工作目录,然后重新启动。

But if there is the project there, press finish. If it complains about the project already existing, go back to the wizard menu and change it to use a wizard. Select a Java wizard and then finish. Often this will work, but only if you first got the "Import Projects" menu to recognize the project in the first place.

但如果那里有项目,请按完成。如果它抱怨项目已经存在,请返回向导菜单并将其更改为使用向导。选择 Java 向导,然后完成。通常这会起作用,但前提是您首先获得“导入项目”菜单以首先识别项目。

It may take several attempts to get this to work! But once it is set up, it works fine.

可能需要多次尝试才能使其正常工作!但是一旦设置,它就可以正常工作。

So, in summary: is ispossible to get EGit to use the default project location for the git clone, but in my experience it may inexplicably require several attempts.

因此,简言之:是可能获得例如:It使用默认的项目位置为git的克隆,但以我的经验,可能莫名其妙地需要多次尝试。

回答by jcfolsom

Nope. There's no way to get this to work. You can't use egit to checkout a git project into the workspace and if you check it out elsewhere and try to copy it into the workspace, you will lose your connection to the remote repository. If you want VCS that works, use svn or mercurial.

不。没有办法让它发挥作用。您不能使用 egit 将 git 项目检出到工作区中,如果您在其他地方检出并尝试将其复制到工作区中,您将失去与远程存储库的连接。如果您希望 VCS 有效,请使用 svn 或 mercurial。