简体   繁体   English

git pull --rebase - 远程重新定位到本地分支?

[英]git pull --rebase — is the remote rebased onto the local branch?

I have been reviewing some Git basics and in this Atlassian documentation about pulling, merging and rebasing there is one thing I don't really understand. 我一直在审查一些Git基础知识,在这篇关于拉动,合并和重新定位的 Atlassian文档中有一件事我不太了解。 The base state of the branches is like this (there are actual images on the page, I can't post them with my reputation): 分支的基本状态是这样的(页面上有实际图像,我不能用我的名字发布它们):

                         A - B - C (Master on remote origin)
                       / 
(Local origin/master) D - E - F - G (Local master)

Now we want to pull changes from the remote and rebase them. 现在我们想从遥控器中提取变化并重新定义它们。 I would have expected, from reading other documentation and playing around with rebase, that git pull --rebase would replay the commits EFG on top of ABC . 我希望,通过阅读其他文档和玩rebase, git pull --rebase将在ABC之上重播提交EFG But instead the Atlassian tutorial says the result looks like that: 但相反,Atlassian教程说结果如下:

                         A - B - C (Master on remote origin)
                       / 
(Local origin/master) D - E - F - G  -  A - B - C (Local master)

So the remote changes got rebased onto the local branch. 因此,远程更改被重新定位到本地分支。 I didn't think it worked like that (at least not without special commands) and it also seems more invasive than the alternative. 我认为它没有那样工作(至少没有特殊命令),它似乎也比其他选择更具侵略性。 If you were to push now, you'd rewrite lots of the remote's history after all. 如果你现在要推,你毕竟重写了很多遥控器的历史。

Is the documentation correct here and in which cases does it happen like that? 这里的文档是否正确以及在哪种情况下会发生这种情况? Most descriptions seem to imply or show that the remote branch is fetched and your local one rebased on top of it, which also seems to make the most sense. 大多数描述似乎暗示或显示远程分支被取出,而本地的分支在它之上重新定位,这似乎也是最有意义的。

I guess I must be misunderstanding something or I'm misreading the figures. 我想我一定是误解了一些事情,或者我误读了这些数字。

You're absolutely right, that tutorial is incorrect. 你是绝对正确的,那个教程是不正确的。 What you expected (and observed) is what git pull --rebase does. 你期望(和观察到的)是git pull --rebase所做的。 The Git documentation says in man git-pull : Git文档在man git-pull

 -r --rebase[=false|true|merges|preserve|interactive] 

When true, rebase the current branch on top of the upstream branch after fetching. 如果为true,则在获取后将当前分支重新绑定在上游分支的顶部。 If there is a remote-tracking branch corresponding to the upstream branch and the upstream branch was rebased since last fetched, the rebase uses that information to avoid rebasing non-local changes. 如果存在与上游分支对应的远程跟踪分支,并且自上次提取以来上游分支已重新定位,则rebase使用该信息来避免重新定位非本地更改。

With current branch they're referring to the locally checked-out branch, with upstream branch they're referring to the remote branch. 对于当前分支,它们指的是本地签出的分支, 上游分支它们指的是远程分支。 Note that --rebase is equivalent to --rebase=true . 请注意--rebase等效于--rebase=true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM