git 如何在 Eclipse 中使用 egit 同步 master 和 origin/master?

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

How do I synchronize master and origin/master using egit in eclipse?

eclipsegitegit

提问by Mark Fisher

I created a local git repository, and I push changes from it to a gitosis remote that I created with

我创建了一个本地 git 存储库,并将更改从它推送到我创建的 gitosis 远程

git init my_git
git remote add origin git@server:my_git
... various adds and commits
git push origin master:refs/heads/master

Now, I edit and commit changes locally in eclipse, and when I commit, I see (using qgit) that it moves my masterbranch to that version.

现在,我在 eclipse 中本地编辑和提交更改,当我提交时,我看到(使用 qgit)它将我的master分支移动到该版本。

However, it also shows me that origin/masteris at the previous version.

但是,它也向我显示origin/master了以前的版本。

git statuson command line shows me everything is up to date:

git status在命令行上向我显示一切都是最新的:

$ git status
# On branch master
nothing to commit (working directory clean)

I can see the differences in versions with

我可以看到版本的差异

git diff origin/master

If i do git pushon my command line, then qgit shows me the origin/masterbranch is now at same place as my master.

如果我git push在命令行上这样做,那么 qgit 会显示origin/master分支现在与我的master.

I can't work out how to configure the "remote / push" or "remote / configure push to upstream" dialog in eclipse to do the same thing as a command line git pushto move the origin/masterto the same level as the master.

我不能工作了如何配置“远程/推”或“远程/配置推给上游”对话框在Eclipse中做同样的事情作为一个命令行git push来移动origin/master到相同的水平master

I always have to do the command line push to make the origin/mastercome up to the same place as master.

我总是要做的命令行推使origin/master上来相同的地方master

Q1. Can anyone tell me how to do this in eclipse?

一季度。谁能告诉我如何在日食中做到这一点?

Q2. What is the command line version of git pushdoing that the eclipse version doesn't do?

Q2。git pusheclipse 版本不做的命令行版本是什么?

Q3. Are my assumptions that masteris my local HEAD pointer and origin/masteris the remote server's view of the current HEAD correct?

Q3。我的假设是否master是我的本地 HEAD 指针,以及origin/master远程服务器对当前 HEAD 的看法是否正确?

采纳答案by Mark Longair

Going by the relevant part of egit's documentationyou can either:

通过egit 文档的相关部分,您可以:

  • click the "Add all branches spec" button, to push all of your local branches to ones with the same name in the remote repository, or
  • (the much safer option) just select masterunder both "Source ref" and "Destination ref" to only push your masterbranch
  • 单击“添加所有分支规范”按钮,将所有本地分支推送到远程存储库中具有相同名称的分支,或
  • (更安全的选项)只需master在“Source ref”和“Destination ref”下选择只推送你的master分支

The remote-tracking branch origin/masteris usually updated by git fetch(which is part of what git pulldoes), but with command line git, the remote-tracking branch is alsoupdated on a successful push to the branch in the remote repository that's being tracked. It's possible that Egit, being based one of the pure Java implementations of git, JGit, rather than the command-line tools, doesn't update origin/masteron a successful push in the same way. If that's the case, you can just do a fetchto update origin/master.

远程跟踪分支origin/master通常由git fetch(这是什么的一部分git pull)更新,但是使用命令行 git,远程跟踪分支也会在成功推送到正在跟踪的远程存储库中的分支时更新。基于 git 的纯 Java 实现之一JGit而不是命令行工具的Egit 可能不会origin/master以相同的方式在成功推送时更新。如果是这种情况,您只需执行 fetch即可更新origin/master



Update: It seems that this is a known bug in EGit (not the underlying JGit) - the bug report is here:

更新:这似乎是 EGit 中的一个已知错误(不是底层的 JGit)——错误报告在这里:

回答by Mark Fisher

An update to this, I was using eclipse Helios, and I've upgraded to Indigo, with the latest version of egit, and the fix appears to be active, as I'm no longer having to pull after a push.

对此的更新,我正在使用 eclipse Helios,并且我已经升级到 Indigo,使用最新版本的 egit,并且修复似乎处于活动状态,因为我不再需要在推送后拉。