如何在 EGit 中创建远程 git 存储库并将其链接到现有的 Eclipse 项目?

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

How do I create a remote git repository in EGit and link it to an existing Eclipse project?

eclipsegitegit

提问by Dan Largo

I am using Eclipse Helios and EGit. I am new to Git. I have an existing Eclipse project for an Android app I would like to place in Git. Can someone please share some instructions on how to setup a Git repo on a shared folder, and place the existing project into this git repo using EGit? I have tried a variety of options with no success.

我正在使用 Eclipse Helios 和 EGit。我是 Git 的新手。我有一个现有的 Eclipse 项目,用于我想放在 Git 中的 Android 应用程序。有人可以分享一些有关如何在共享文件夹上设置 Git 存储库,并使用 EGit 将现有项目放入此 git 存储库的说明吗?我尝试了多种选择,但都没有成功。

Thanks!

谢谢!

回答by Asenar

I had the same question (how to do it in Eclipse / eGit), and I just found the answer to the question stated in the title :

我有同样的问题(如何在 Eclipse/eGit 中进行),我刚刚找到了标题中所述问题的答案:

  1. go in Window> Show Views> Othersselect Git repositories
  2. expand the repository to see "Remotes", right click and Create Remote
  3. choose the option : fetch will tell eclipse you're only allowed to read (which is the correct option if you don't want/have the right to push on that repo). then name that remote repository like you want (the first is usually named "origin", but you can have "prod", "test-server", ...)
  4. click on change to specify the uri of the repository. You can paste on the first field the complete uri you would type after "git clone".
  5. "Finish" then "Save and Push" or "Save and Fetch" according to what you choosed in 3°
  1. 进入Window> Show Views>Others选择Git repositories
  2. 展开存储库以查看“遥控器”,右键单击并 Create Remote
  3. 选择选项: fetch 将告诉 eclipse 您只允许阅读(如果您不想/无权推动该回购,这是正确的选项)。然后根据需要命名该远程存储库(第一个通常命名为“origin”,但您可以使用“prod”、“test-server”...)
  4. 单击更改以指定存储库的 uri。您可以在第一个字段上粘贴您将在“git clone”之后键入的完整 uri。
  5. 根据您在 3° 中选择的内容,“完成”然后“保存并推送”或“保存并获取”

Also, for creating a new project in Eclipse from an existing git repository with eGit, all you have to do is to go in File > Import...and choosing Git/Projects from Git. Then follow the steps

此外,要使用 eGit 从现有的 git 存储库在 Eclipse 中创建新项目,您所要做的就是进入File > Import...并从 Git 中选择 Git/Projects。然后按照步骤

回答by Adam Dymitruk

You can do everything from the command line instead:

您可以改为从命令行执行所有操作:

Do this in the root of the project:

在项目的根目录中执行此操作:

git init

Do the same in the folder where you want your blessed or central repository:

在您想要祝福或中央存储库的文件夹中执行相同操作:

git init --bare

In the local repository, add a readme file and commit it:

在本地存储库中,添加一个自述文件并提交:

echo "testing" > readme
git add readme   
git commit -m "initial commit"

Now link and push your changes to the central repository:

现在链接并将您的更改推送到中央存储库:

git remote add origin //server/share/repodir
git push -u origin master

Hope this gets you started.

希望这能让你开始。

You can use egit later if you like, but there is nothing wrong with using git separately.

如果您愿意,您可以稍后使用 egit,但单独使用 git 没有任何问题。

回答by Paul Webster

See http://wiki.eclipse.org/EGit/User_Guide

http://wiki.eclipse.org/EGit/User_Guide

If you only want one project in your git repo, Team>Share Project will turn that project into a git repo. You can then create another repo on your share, and push your project repo to the shared folder repo.

如果你只想要一个项目在你的 git repo 中,Team>Share Project 会将该项目变成一个 git repo。然后,您可以在您的共享上创建另一个存储库,并将您的项目存储库推送到共享文件夹存储库。

If you want a repo with multiple projects, your best bet is to create the project in an external location to the workspace. Then you can create the git repo in the folder above your project.

如果您想要一个包含多个项目的存储库,最好的办法是在工作区的外部位置创建项目。然后你可以在你的项目上面的文件夹中创建 git repo。