gpt4 book ai didi

git rebase upstream/master 与 git pull --rebase upstream master

转载 作者:IT王子 更新时间:2023-10-29 00:51:21 49 4
gpt4 key购买 nike

git rebase upstream/mastergit pull --rebase upstream master 之间有区别吗?如果有,那是什么?远程可以是任何远程,不一定是上游。

最佳答案

git pull --rebasefetch (git fetch)首先,更新 upstream/master 提交。

如果您只是 rebase 而不先更新 upstream/master,您将不会得到相同的结果。

我在“master branch and 'origin/master' have diverged, how to 'undiverge' branches'?”中说明了这一点


SnakE提及 in the comments git pull --rebase 不完全是 git fetch && git rebase origin/master
参见“what does "git pull --rebase" do?

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

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

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

这里:

  • origin/master 是新更新的 origin/master (B')
  • B 是旧的 origin/master(在 fetch 更新之前)
  • master 是要在 origin/master
  • 之上重播的分支

这与 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 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 与 git pull --rebase upstream master,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15602037/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com