git rebase upstream/master vs git pull --rebase upstream master

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

git rebase upstream/master vs git pull --rebase upstream master

gitgit-rebasegit-pull

提问by Dennis

Is there a difference between git rebase upstream/masterand git pull --rebase upstream master, and if so, what? The remote could be any remote, not necessarily upstream.

有没有之间的差异git rebase upstream/mastergit pull --rebase upstream master,如果是这样,是什么?遥控器可以是任何遥控器,不一定是上游。

回答by VonC

The git pull --rebasewill fetch (git fetch)first, updating upstream/mastercommits.

git pull --rebase取(git fetch第一,更新upstream/master的提交。

If you just rebase withoutfirst updating upstream/master, you won't get the same result.

如果您只是在没有先更新的情况下重新设置基准upstream/master,您将不会得到相同的结果。

I illustrate it in "masterbranch and 'origin/master' have diverged, how to 'undiverge' branches'?"

我说明了它的“master分支和‘ origin/master’有分歧,如何‘undiverge’分支?



SnakEmentions in the commentsthat git pull --rebaseisn't exactlygit fetch && git rebase origin/master.
See "what does "git pull --rebase" do?"

SnakeE在评论中提到git pull --rebase完全是git fetch && git rebase origin/master.
看看“”git pull --rebase做什么的?

(origin/master)
   |
A--B--C (master)
 \ 
  B'--D (actual origin/master after changing B and force pushing)

What git pull --rebasedoes, in this case, is:

是什么git pull --rebase呢,在这种情况下,就是:

git fetch origin
git rebase --onto origin/master B master

Here:

这里:

  • origin/master is the new updated origin/master(B')
  • Bis the old origin/master(before a fetch updated it)
  • masteris the branch to replay on top of origin/master
  • origin/master 是新的更新origin/master( B')
  • B是旧的origin/master(在 fetch 更新它之前)
  • master是重播的分支 origin/master

This differs from git fetch+ git rebase origin/masterin that the pull --rebasecommand tries to find out which commits are reallyyour local ones, and which had come from upstream in an earlier fetch.

这与git fetch+ 的不同之处git rebase origin/master在于该pull --rebase命令试图找出哪些提交确实是您的本地提交,哪些提交来自上游的早期获取。

To do this, it looks at the reflog of the remote tracking branch (origin/master, in this case). This reflog represents the tips of successive git fetchoperations on origin, in "most recent first" order.

For each reflog entry, (origin/master@{1}, then ...{2}, and so on) it checks if that commit is an ancestor of the current branch head master. As soon as it finds one, it picks it as the starting point for the rebase (Bin the example above).

为此,它查看远程跟踪分支的引用日志(origin/master在本例中为 )。此 reflog 表示对 的连续git fetch操作的提示origin,按“最近在先”的顺序。

对于每个 reflog 条目, ( origin/master@{1}、 then...{2}等等) 它会检查该提交是否是当前分支 head 的祖先master。一旦找到一个,它就会选择它作为 rebase 的起点(B在上面的例子中)。