如何使用 Eclipse EGit 从我的服务器 git 存储库下载/克隆一个新分支到我 PC 中已经创建的本地 git 存储库

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

How to download/clone a new branch from my server git repository into an already created local git repository in my PC with Eclipse EGit

eclipsegiteclipse-pluginegitgit-clone

提问by jdias

This is driving me crazy.

这真让我抓狂。

I created a git repository in a Linux server hosted by my hosting company.

我在托管公司托管的 Linux 服务器中创建了一个 git 存储库。

I cloned it to a local copy using Eclipse EGit.

我使用 Eclipse EGit 将其克隆到本地副本。

I then created a branch in the original git repository in the server.

然后我在服务器的原始 git 存储库中创建了一个分支。

How do I copy the branch to my local copy using Eclipse EGit?

如何使用 Eclipse EGit 将分支复制到我的本地副本?

When I open Git Repositories inside EGit I see:

当我在 EGit 中打开 Git 存储库时,我看到:

- Local
-- master

- Remote Tracking
-- origin/development
-- origin/master

How can I get the origin/development in my local using EGit?

如何使用 EGit 在我的本地获取起源/发展?

I know I could create a new clone, but I don't want to do that as I believe there must be a way to get only the new branch.

我知道我可以创建一个新的克隆,但我不想这样做,因为我相信必须有一种方法可以只获取新分支。

Second question- where is the pull command inside EGit? I was able to find the fetch command, but when I run it it says that there is nothing to fetch. The RefSpec is:

第二个问题- EGit 中的 pull 命令在哪里?我能够找到 fetch 命令,但是当我运行它时,它说没有什么可获取的。RefSpec 是:

+refs/heads/*:refs/remotes/origin/*

Third question- is there a way to process git commands from a command line inside Eclipse in my Windows system? I thought about trying to do a pull from a command line, but I can't find it in my local system.

第三个问题- 有没有办法在我的 Windows 系统中从 Eclipse 内的命令行处理 git 命令?我想尝试从命令行执行拉取操作,但在本地系统中找不到它。

Thank you.

谢谢你。

采纳答案by Karl Bielefeldt

Your fetch is up to date because you already have everything copied to your local repository. A pull will merge origin/developmentinto master, which isn't what you want. You want to create a new branch with origin/developmentas the starting point. I don't know how to do it with egit, but on the command line, you do:

您的提取是最新的,因为您已经将所有内容复制到本地存储库。拉将合并origin/development到主人,这不是你想要的。您想创建一个新分支origin/development作为起点。我不知道如何使用 egit,但在命令行上,您可以:

git checkout -b development origin/development

回答by mozzbozz

I've also been searching around some hours to find out how to get a remote branch in Eclipse EGit...

我也一直在搜索几个小时,以了解如何在 Eclipse EGit 中获取远程分支...

The solution is stated in this Bugreport. And it is really easy if you know how to do it - no need for using the command line version of git, which - even though it works in 99% of all cases - can be risky as I already had problems that it interfered with Eclipse and EGit.

解决方案在此 Bugreport 中说明。如果您知道如何去做,这真的很容易 - 不需要使用 git 的命令行版本,这 - 即使它在 99% 的情况下都有效 - 可能有风险,因为我已经遇到了它干扰 Eclipse 的问题和EGit。

Just follow these steps:

只需按照以下步骤操作:

  1. First make sure you have opened the EGit Repository view. If you haven't opened it already, go to "Window → Show View → Other..." and from there select "Git → Git Repositories".
  2. In the Repository viewchoose "Branches → Remote Tracking". You should see your remote branches there already (example: origin/new_feature).
  3. Right click on the remote branch you wish to have with your local branches. Choose "Create Branch..."
  4. The default values should be OK. Normally you should not change anything here.Please note that you should notchange the "Pull strategy" to something else than "Merge" if you don't know what you are doing. Otherwise pulling upstream changes might result in a loss of data.
  5. Click on OK "Finish" and you are done :)
  1. 首先确保您已打开 EGit Repository view。如果您还没有打开它,请转到“窗口 → 显示视图 → 其他...”,然后从那里选择“Git → Git 存储库”。
  2. Repository view选择“分支→远程跟踪”。您应该已经在那里看到您的远程分支(例如:)origin/new_feature
  3. 右键单击您希望与本地分支一起使用的远程分支。选择“创建分支...”
  4. 默认值应该没问题。通常你不应该在这里改变任何东西。请注意,您应该不会改变“拉动战略”的东西不是“合并”否则,如果你不知道自己在做什么。否则,拉取上游更改可能会导致数据丢失。
  5. 点击确定“完成”,你就完成了:)

回答by razvang

I have been facing the same problem, and here is how I solved it:

我一直面临同样的问题,这是我解决它的方法:

  1. Open Git Perspective

  2. First you must have the branch that you want to check out, in your repository under Remote Tracking. My problem was that I couldn't see the remote branch here, so in order to solve this - execute a Pullon the repository, and this command should get you all the branches under Remote Tracking

  3. right click the (remote) Branch, Check Out, Check out as new local branch
  1. 开放 Git 视角

  2. 首先,您必须在远程跟踪下的存储库中拥有要检出的分支。我的问题是我在这里看不到远程分支,所以为了解决这个问题 -在存储库上执行一个取,这个命令应该让你得到远程跟踪下的所有分支

  3. 右键单击(远程)分支,签出,签出为新的本地分支

回答by RoshanS

To get other branches in sts , if pull didn't work then try this Team >> Remote>> Cofigure fetch from upstream stream>Advanced> Check branch you want in source ref: > then add spec

要在 sts 中获取其他分支,如果 pull 不起作用,请尝试此 Team >> Remote>> Cofigure fetch from upstream stream>Advanced> 在源引用中检查您想要的分支:> 然后添加规范