git 如何将 GitHub 和 Bitbucket 存储库导入 Eclipse Mars?

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

How to import GitHub and Bitbucket repositories into Eclipse Mars?

eclipsegitgithubbitbucketegit

提问by Peter Korinek TellusTalk

I installed Eclipse Mars enabled the Git perspective and imported a repository. It looks fine, but Eclipse is not behaving normal I can't create new files and search is not finding anything outside the file I'm in. What is the proper way to import repositories/projects from GitHub, Bitbucket and other Git Hosts?

我安装了 Eclipse Mars,启用了 Git 透视图并导入了一个存储库。看起来不错,但 Eclipse 的行为不正常 我无法创建新文件,并且搜索在我所在的文件之外找不到任何内容。从 GitHub、Bitbucket 和其他 Git 主机导入存储库/项目的正确方法是什么?

回答by Verhagen

First you need to clone the (git) repository in Eclipse.

首先,您需要在 Eclipse 中克隆 (git) 存储库。

Steps to clone git repo in Eclipse

在 Eclipse 中克隆 git repo 的步骤

  • Go to GitHub, or BitBucket, and copy the URL of the repo to clone
  • In Eclipse, Open the perspective Git
  • Use the shortcut icon Clone a Git Repository ...(the icons are shown on the view Git Repositories)
  • The dialog Clone Git Repositoryopens, with the page Source Git Repository
  • (The url of the git repo, should already be filled in, at the field uri)
  • 转到 GitHub 或 BitBucket,然后复制 repo 的 URL 进行克隆
  • 在 Eclipse 中,打开透视图Git
  • 使用快捷图标Clone a Git Repository ...(图标显示在视图Git Repositories 上
  • 对话框Clone Git Repository打开,页面为Source Git Repository
  • (git repo 的 url 应该已经填写在uri字段中)

TIP:The field urican not be edited. Use the other field, like Host, repository Path, etc to correct the url if required.

提示:字段uri无法编辑。如果需要,使用其他字段,如Hostrepository Path等来更正 url。

  • Press the button Next
  • The page Branch Selectionopens
  • All branches from the remote git repository are now shown
  • (Mark the branches you like to clone, by default all branches are checked for cloning)
  • Press the button Next
  • The page Local Destinationopens
  • Make sure you select the correct location, where the local clone of the repository should go (something like /home/<user>/git)
  • 下一步按钮
  • 页面分支选择打开
  • 现在显示来自远程 git 存储库的所有分支
  • (标记你喜欢克隆的分支,默认所有分支都检查克隆)
  • 下一步按钮
  • 本地目的地页面打开
  • 确保您选择了正确的位置,即存储库的本地克隆应该放在的位置(类似于/home/<user>/git

TIP:Make sure that you do NOTclone the git repository inside the Eclipse workspace directory!

提示:确保不要在 Eclipse 工作区目录中克隆 git 存储库!

  • Select from the drop-down Initial branchthe branch you like to start working on. (Default is the masterbranch. Can also easily be changed later.)
  • Press the button Finish, to start the cloning job.
  • 从下拉初始分支中选择您想要开始工作的分支。(默认是master分支。以后也可以轻松更改。)
  • 按下按钮Finish,开始克隆工作。

After successful cloning of the git repository, the project(s) in the git repository can be imported into Eclipse as (Eclipse) projects.

成功克隆git存储库后,git存储库中的项目可以作为(Eclipse)项目导入Eclipse。

Import project in Eclipse

在 Eclipse 中导入项目

Open the Eclipse perspective Java

打开 Eclipse 透视图Java

Maven Project

Maven项目

This will import Maven project(s) (based on pom.xmlfile(s)) as Eclipse project(s)

这将导入 Maven 项目(基于pom.xml文件)作为 Eclipse 项目

  • From the view Package Explorerselect right mouse button menu: Import...or use the Eclipse menu: File -> Import...
  • The dialog Importopens, with the page Select
  • Select from the tree: Maven -> Existing Maven Projects
  • Press the button Next
  • The page Maven Projectopens
  • Choose the Root Directoryto scan for Maven projects. Use the button Browse, to go to the just cloned git repository (/home/<user>/git)
  • Once the location is selected, the Projectsshould appear, in the form of located pom.xmlfiles.
  • (Normally all projects are selected. At a 2nd import, some may be grayed out, as they already exist in the Eclipse Package Explorer, as project)
  • Press the button Finishto import the Maven project as Eclipse projects
  • 从视图Package Explorer 中选择鼠标右键菜单:Import...或使用 Eclipse 菜单:File -> Import...
  • 对话框导入打开,页面选择
  • 从树中选择:Maven -> Existing Maven Projects
  • 下一步按钮
  • Maven 项目页面打开
  • 选择根目录来扫描 Maven 项目。使用按钮Browse,转到刚刚克隆的 git 存储库 ( /home/<user>/git)
  • 选择位置后,项目应以定位pom.xml文件的形式出现。
  • (通常所有项目都被选中。在第二次导入时,有些可能会变灰,因为它们已经作为项目存在于 Eclipse Package Explorer 中)
  • 完成按钮将 Maven 项目作为 Eclipse 项目导入

Eclipse

In case the git projects do contain the typical Eclipse configuration files / directory (like: .project, .classpath, .settings), then they can be imported as Standard Eclipse projects

如果git的项目都包含了典型的Eclipse配置文件/目录(如:.project.classpath.settings),这时可以将它们导入为标准的Eclipse项目

  • From the view Package Explorerselect right mouse button menu: Import...or use the Eclipse menu: File -> Import...
  • The dialog Importopens, with the page Select
  • Select from the tree: General -> Existing Projects into Workspace
  • Press the button Next
  • Choose the Select Root Directoryto scan for Eclipse projects. Use the button Browse, to go to the just cloned git repository (/home/<user>/git)
  • (Select from the Optionsthe check box Search for nested projectsin case the imported project contains nested Eclipse projects)
  • (Normally all projects are selected. At a 2nd import, some may be grayed out, as they already exist in the Eclipse Package Explorer, as project)
  • Press the button Finishto import the Maven project as Eclipse projects
  • 从视图Package Explorer 中选择鼠标右键菜单:Import...或使用 Eclipse 菜单:File -> Import...
  • 对话框导入打开,页面选择
  • 从树中选择:General -> Existing Projects into Workspace
  • 下一步按钮
  • 选择Select Root Directory以扫描 Eclipse 项目。使用按钮Browse,转到刚刚克隆的 git 存储库 ( /home/<user>/git)
  • (如果导入的项目包含嵌套的 Eclipse 项目,请从选项中选择搜索嵌套项目复选框)
  • (通常所有项目都被选中。在第二次导入时,有些可能会变灰,因为它们已经作为项目存在于 Eclipse Package Explorer 中)
  • 完成按钮将 Maven 项目作为 Eclipse 项目导入

回答by Peter Korinek TellusTalk

Prerequisites GitHub/Bitbucket:

先决条件 GitHub/Bitbucket:

Get an GitHub/Bitbucket account.

获取一个 GitHub/Bitbucket 帐户。

  • List item
  • Create a new repository in GitHub/Bitbucket
  • Make a branch of your "master" in your new repository, it is good practice not to do changes in directly in the "master" but merging the changes from a branch.
  • 项目清单
  • 在 GitHub/Bitbucket 中创建一个新存储库
  • 在新存储库中创建“master”的分支,最好不要直接在“master”中进行更改,而是合并来自分支的更改。

Prerequisites on your computer:

在您的计算机上的先决条件:

  • Install Eclipse Mars
  • 安装 Eclipse 火星

Setup the git project in Eclipse

在 Eclipse 中设置 git 项目

  • Open perspective "Resource"

    • Menu: Window / Perspective / Open Perspective / Other and choose "Resource"
  • Import your GitHub/Bitbucket branch

    • Menu: File / Import, a wizard opens
    • Wizard (Select): Under "Git" choose "Project from Git" and press "Next"
    • Wizard (Select Repository Source): Choose "Clone URI" and press "Next"
    • Wizard (Source Git Repository): At top "Location / URI:" paste in your GitHub/Bitbucket Url. (In GitHub/Bitbucket site right click your repository link and choose copy link address)
    • Under Authentication fill in your GitHub/Bitbucket user and password and press "Next"

    • Wizard (Branch Selection): Only check your branch, deselect all others and press "Next"

    • Wizard (Local Destination): Choose a folder where you like to keep your git project, don't put it in your workspace folder and press "Next".

    • Wizard (Select a wizard to use for importing projects): Select "Import as general project" and press "Next"

    • Wizard (Import projects): Press "Finish"

  • 打开透视图“资源”

    • 菜单:窗口/透视图/打开透视图/其他并选择“资源”
  • 导入你的 GitHub/Bitbucket 分支

    • 菜单:文件/导入,向导打开
    • 向导(选择):在“Git”下选择“Project from Git”,然后按“Next”
    • 向导(选择存储库源):选择“克隆 URI”并按“下一步”
    • 向导(源 Git 存储库):在顶部的“位置/URI:”粘贴到您的 GitHub/Bitbucket Url。(在 GitHub/Bitbucket 站点中右键单击您的存储库链接并选择复制链接地址)
    • 在身份验证下填写您的 GitHub/Bitbucket 用户和密码,然后按“下一步”

    • 向导(分支选择):只检查您的分支,取消选择所有其他分支,然后按“下一步”

    • 向导(本地目标):选择一个你想保存你的 git 项目的文件夹,不要把它放在你的工作区文件夹中,然后按“下一步”。

    • 向导(选择用于导入项目的向导):选择“作为常规项目导入”,然后按“下一步”

    • 向导(导入项目):按“完成”

The project should now be visible in the "Project Explorer"

该项目现在应该在“项目资源管理器”中可见

Create the ".gitignore" file

创建“.gitignore”文件

This is importent or your code will be mixed with Eclipse files

这很重要,否则您的代码将与 Eclipse 文件混合

In "Project Explorer" right click your project folder an then New / File enter ".gitignore" at the "File Name" prompt and press "Finish"

在“项目资源管理器”中右键单击您的项目文件夹然后新建/文件在“文件名”提示下输入“.gitignore”并按“完成”

Paste the following in to the file.

将以下内容粘贴到文件中。

# eclipse specific git ignore
*.pydevproject
.project
.metadata
bin/**
tmp/**
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

Finally keep your Eclipse project in sync with GitHub/Bitbucket

最后让你的 Eclipse 项目与 GitHub/Bitbucket 保持同步

  • Menu: Window / Perspective / Open Perspective / Other and choose "Git"

  • In the "Git Perspective" drag files from "Unstaged Changes" to "Staged Changes" Enter a "Commit Message" describing your code changes and finally press "Commit and Push"

  • 菜单:窗口/透视图/打开透视图/其他并选择“Git”

  • 在“Git Perspective”中将文件从“Unstaged Changes”拖到“Staged Changes”输入描述代码更改的“Commit Message”,最后按“Commit and Push”