git 如何在 Eclipse 中添加 GitLab 存储库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24304759/
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 18:13:18  来源:igfitidea点击:

How to add GitLab repository in Eclipse?

eclipsegitgitlab

提问by Monica Tandyria

How to add Git-Lab on Eclipse?

如何在 Eclipse 上添加 Git-Lab?

So that I can just push or fetch from GitLab. I am a newbie in this, please give more explanation.

这样我就可以从 GitLab 推送或获取。我是这方面的新手,请多多解释。

回答by manuelvigarcia

I Preparation

我准备

Make sure you have eGit in Eclipse:

确保您在 Eclipse 中有 eGit:

  1. Help -> Installation details
  2. See that "Eclipse Git Team provider" is in the list.
  1. 帮助 -> 安装详情
  2. 看到“Eclipse Git Team provider”在列表中。

If it is not installed, follow the indications in the answerfrom @VonC

如果未安装,请按照@VonC的回答中的说明进行操作

Make sure you have the URL to the repository in GitLab. Something like https://gitlab.com/<someusername>/<somerepository>You get it from gitlab.com when you are at the overview page for the project:

确保您拥有 GitLab 中存储库的 URL。像https://gitlab.com/<someusername>/<somerepository>你从gitlab.com得到它,当你在项目的概述页面:

  • Menu (the hamburger icon ≡, 3 horizontal lines),-> projects, then click in the one you want to work with from eclipse. Now you are in the overview page. Right beneath the name of the project and its description there are a few buttons to allow you to perform some actions. One of those buttons is a selector for SSH/HTTPS protocols. For now, select HTTPS and copy the URL that follows it: that is the URL to the project.
  • 菜单(汉堡包图标 ≡,3 条水平线),-> 项目,然后在 Eclipse 中单击要使用的项目。现在您位于概览页面中。在项目名称及其描述的正下方,有几个按钮可让您执行某些操作。其中一个按钮是 SSH/HTTPS 协议的选择器。现在,选择 HTTPS 并复制其后的 URL:即项目的 URL。

II Now clone the repository locally, using Eclipse eGit.

II 现在使用 Eclipse eGit 在本地克隆存储库。

These steps have been tested in Eclipse Kepler and Eclipse Luna. Rumor has it that they are outdated and might not work as indicated. If you use a newer Eclipse, take care and post back the new steps :-)

这些步骤已经在 Eclipse Kepler 和 Eclipse Luna 中进行了测试。有传言说它们已经过时,可能无法正常工作。如果您使用较新的 Eclipse,请注意并回发新步骤 :-)

  1. Window -> Open Perspective -> Other
  2. Search for "Git", select it, and click "OK"
  3. Click the button with an arrow and the tool tip "Clone a Git repository and add the clone to this view"
  4. In the "Source Git Repository" wizard:
    • URI: the URL from the repository in GitLab, like https://gitlab.com/<someusername>/<somerepository>
    • eGit has filled in the host and repository path for you.
    • Leave the connection as it is (https and no port) and fill in the details for the authentication: user and password you use to log in GitLab.com.
    • If you tick the "Store in Secure Store," Eclipse will handle user/password for you from now on; I do it, but it is not advisable if you share Eclipse installation with someone else, or you do not trust your PC to hold your passwords.
    • Click next
  5. Branch selection wizard.
    • If there are more than one branch in the repository, you may now choose which one you want to clone locally, the one with which you want to interact. You may also choose to clone all branches to have them available.
    • Once you are done, click Next
  6. Local destination wizard.
    • You may now choose where you want to place your local Git repository. eGit defaults to a subdirectory under you user, unrelated to eclipse, it works well. If you do not like it, change to your liking.
    • As with other Git installations, it will name the GitLab.com repository as "origin". You may also change that if you really want.
    • In the projects box check the "Import all projects" and, if you work with "Working Sets", you may choose now in which one to place it.
    • Click Finish.
  1. 窗口 -> 打开透视图 -> 其他
  2. 搜索“Git”,选择它,然后单击“确定”
  3. 单击带有箭头的按钮和工具提示“Clone a Git repository and add the clone to this view”
  4. 在“Source Git Repository”向导中:
    • URI:来自 GitLab 存储库的 URL,例如 https://gitlab.com/<someusername>/<somerepository>
    • eGit 已为您填写了主机和存储库路径。
    • 保持连接不变(https 和无端口)并填写身份验证的详细信息:用于登录 GitLab.com 的用户名和密码。
    • 如果您勾选“Store in Secure Store”,Eclipse 将从现在开始为您处理用户/密码;我这样做了,但是如果您与其他人共享 Eclipse 安装,或者您不信任您的 PC 来保存您的密码,则不建议这样做。
    • 点击下一步
  5. 分支选择向导。
    • 如果存储库中有多个分支,您现在可以选择要在本地克隆的分支,以及要与之交互的分支。您也可以选择克隆所有分支以使其可用。
    • 完成后,单击下一步
  6. 本地目标向导。
    • 您现在可以选择要放置本地 Git 存储库的位置。eGit 默认为你用户下的子目录,与 eclipse 无关,效果很好。如果您不喜欢它,请根据自己的喜好进行更改。
    • 与其他 Git 安装一样,它会将 GitLab.com 存储库命名为“origin”。如果你真的想要,你也可以改变它。
    • 在项目框中选中“导入所有项目”,如果您使用“工作集”,您现在可以选择将其放置在哪个项目中。
    • 单击完成。

eGit now works for a bit and shows you the newly cloned repository in the view. You have a cloned repository with which you will be able to interact from Eclipse.

eGit 现在工作了一段时间,并在视图中向您显示新克隆的存储库。您有一个克隆的存储库,您可以从 Eclipse 与之交互。

III Now import the project into Eclipse.

III 现在将项目导入 Eclipse。

  1. File -> Import...
  2. Git -> Projects from Git -> Next
  3. Existing local repository -> Next
  4. Select the newly cloned repository -> Next
  5. Import using the New Project Wizard -> Finish
  6. Choose the project type that is hosted in GitLab.com. In my case is "Java Project;" in other occasions it has been "Maven -> Maven Project". Then click Next
  7. Name the project and change the settings you want. As destination, do not use the default location, but navigate to the location of the cloned repository (as used in step 6 in the previous section cloning the repository) -> Next
  8. Verify that the import looks like you want it and click Finish.
  1. 文件 -> 导入...
  2. Git -> 来自 Git 的项目 -> 下一步
  3. 现有的本地存储库 -> 下一步
  4. 选择新克隆的仓库 -> Next
  5. 使用新建项目向导导入 -> 完成
  6. 选择托管在 GitLab.com 中的项目类型。在我的例子中是“Java 项目”;在其他情况下,它是“Maven -> Maven Project”。然后点击下一步
  7. 命名项目并更改所需的设置。作为目标,不要使用默认位置,而是导航到克隆存储库的位置(如上一节克隆存储库的步骤 6 中所用)-> 下一步
  8. 验证导入是否符合您的要求,然后单击完成。

You may now work within Eclipse and use the Team menus to sync and commit and push.

您现在可以在 Eclipse 中工作并使用 Team 菜单来同步、提交和推送。

回答by VonC

The easiest way is to usean Eclipse with EGit (http://www.vogella.com/tutorials/EclipseGit/article.html)

最简单的方法是使用 Eclipse 和 EGit ( http://www.vogella.com/tutorials/EclipseGit/article.html)

See "Compare Eclipse packages" (the standard Eclipse, for instance, has EGit)

请参阅“比较 Eclipse 包”(例如,标准 Eclipse具有 EGit)

This will allow you to add a remote repo url referring to your gitlab repo hosting server.
This isn't specific to gitlab though, and you could add remote repos referring to Github or Bitbucket.
http://wiki.eclipse.org/EGit/User_Guide#Working_with_remote_Repositories

这将允许您添加一个指向您的 gitlab 存储库托管服务器的远程存储库 URL。
不过,这并非特定于 gitlab,您可以添加引用 Github 或 Bitbucket 的远程存储库。
http://wiki.eclipse.org/EGit/User_Guide#Working_with_remote_Repositories

http://wiki.eclipse.org/images/3/35/Egit-0.9-clone-wizard-url-page.png

http://wiki.eclipse.org/images/3/35/Egit-0.9-clone-wizard-url-page.png

回答by Bikramjit Singh

Install Egit in eclipse using Install new software from http://download.eclipse.org/egit/updates.

使用从http://download.eclipse.org/egit/updates安装新软件在 eclipse 中安装 Egit 。

回答by Hajo Thelen

It seems that there is a Mylyn Gitlab Connectornow.

现在似乎有一个Mylyn Gitlab 连接器

I think I'll give it a try

我想我会试一试