git rebase upstream / master vs git pull --rebase upstream master [英] git rebase upstream/master vs git pull --rebase upstream master

查看:312
本文介绍了git rebase upstream / master vs git pull --rebase upstream master的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

> git rebase upstream / master git pull --rebase upstream master 之间是否有区别,if所以呢?远程可以是任何远程的,不一定是上游的。 code>将获取( git fetch 首先,更新 upstream / master 提交。



/ em>第一次更新 upstream / master ,你不会得到相同的结果。



master 分支和' origin / master '已经发散,如何'分支'分支'?/ b>




SnakE 提及在评论中, git pull --rebase 不是正好 git f蚀刻&& git rebase origin / master

请参阅 git pull --rebase do?

 (origin / master)
|
A - B - C(主)
\
B' - D(更改B和强制推后的实际原点/主)

在这种情况下, git pull --rebase 是:

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

这里:


  • origin / master是新更新的 origin / master B'
  • B 是旧的 origin / master (在获取更新之前)

  • master 是在 origin / master


$ b $之上重播的分支b

这与 git fetch + git rebase origin / master 的区别在于 pull --rebase 命令试图找出哪些提交是真正的你的本地提交,哪些提交来自上一次提取的上游。


为此,它查看远程的reflog跟踪分支(在这种情况下 origin / master )。此reflog表示以最近的第一个顺序在 origin 上对 git fetch 操作的提示。



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



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

解决方案

The git pull --rebase will fetch (git fetch) first, updating upstream/master commits.

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

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


SnakE mentions in the comments that git pull --rebase isn't exactly git fetch && git rebase origin/master.
See "what does "git pull --rebase" do?"

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

What git pull --rebase does, in this case, is:

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

Here:

  • origin/master is the new updated origin/master (B')
  • B is the old origin/master (before a fetch updated it)
  • master is the branch to replay on top of origin/master

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

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 fetch operations 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 (B in the example above).

这篇关于git rebase upstream / master vs git pull --rebase upstream master的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆