简体   繁体   English

git rebase分支与祖父母

[英]git rebase branch with grandparent

I am reading about git rebase and was reading through - git-scm 's documentation. 我正在阅读关于git rebase并正在阅读 - git-scm的文档。

I have a specific doubt about using the onto feature of git rebase to rebase a branch to its grandparent (just like the case in above link). 我对使用一个特定的疑问onto混帐底垫功能变基跳转至其祖父(就像在上面的链接的情况下)。
Let us assume we have a branch/commit structure like the following: 我们假设我们有一个分支/提交结构,如下所示:

C1 <- C2 <- C5 <- C6 [master]
         <- C3 <- C4 <- C10 [server]
               <- C8 <- C9 [client]

Now, I want to rebase client brnach onto master . 现在,我想将client brnach改为master I checked out client branch and ran git rebase --onto master server client command. 我检查了client分支并运行git rebase --onto master server client命令。 The resultant structure I got (after merging and fast-forwarding master to client) from this command is: 我从这个命令获得的结果(在合并和快速转发主服务器之后)是:

C1 <- C2 <- C5 <- C6 <- C8' <- C9' [master, client]
         <- C3 <- C4 <- C10 [server]

My doubt is, what if my changes in client branch were depending on C3 commit in server branch. 我怀疑的是,如果client分支中的更改取决于server分支中的C3提交,该怎么办? The resultant code in master branch would certainly fail in such a scenario as rebase does . master分支中的结果代码肯定会在rebase这样的场景中失败。 As far as my knowledge goes, shouldn't the actual result (after merging and fast-forwarding master to client) be like: 据我所知,不应该将实际结果(在合并和快速转发主客户端之后)如下:

 C1 <- C2 <- C5 <- C6 <- C3' <- C8' <- C9' [master, client]
                             <- C4 <- C10 [server]

Can somebody please let me know whether my understanding/concern is wrong? 有人可以让我知道我的理解/关注是否错误?

If you start from 如果你从头开始

C1---C2---C5---C6  master
       \
        C3---C4---C10  server
          \
           C8---C9  client

and you expect the result to be 你希望结果如此

C1---C2---C5---C6---C3'---C8'---C9' master, client
                      \
                       C4---C10  server

Then the misunderstanding is: C3' cannot be the ancestor of C4 . 然后误解是: C3'不能是C4的祖先 That cannot happen here. 这不可能发生在这里。

When you do 当你这样做

git rebase --onto master server client

and, as you put it, changes in client "depend" on changes from C3 , you can resolve the merge and you'll get 而且,正如你所说, 客户端的变化“依赖”来自C3的变化,你可以解决合并,你会得到

C1---C2---C5---C6  master
       \         \
        \         C8'---C9' client
         \
          C3---C4---C10  server

Now, after you merge master and client , and you are ready to rebase server , two scenarios could happen: 现在,在合并主服务器客户端之后 ,您已准备好重新定义服务器 ,可能会发生两种情况:

1. If you kept the changes from C8 that "depend" on C3 in the previous conflict, after you resolve the current conflict git will say 1.如果您在上一次冲突中保留了C8中“依赖” C3的变化,那么在您解决当前冲突后git会说

No changes - did you forget to use 'git add'? 没有变化 - 你忘了使用'git add'吗? If there is nothing left to stage, chances are that something else already introduced the same changes; 如果没有任何东西可以上台, 那么其他东西可能已经引入了同样的变化; you might want to skip this patch . 你可能想跳过这个补丁

When you have resolved this problem, run "git rebase --continue". 解决此问题后,运行“git rebase --continue”。 If you prefer to skip this patch, run "git rebase --skip" instead. 如果您想跳过此补丁,请改为运行“git rebase --skip”。 To check out the original branch and stop rebasing, run "git rebase --abort". 要检出原始分支并停止重新定位,请运行“git rebase --abort”。

You can then do 然后你可以做

git rebase --skip

and you'll get 你会得到的

C1---C2---C5---C6---C8'---C9'  master, client  
                             \         
                              C4'---C10' server

Notice there is no C3' as those changes were applied with C8' . 请注意,没有C3',因为这些更改适用于C8'

2. If you did not keep the changes from C8 that "depend" on C3 in the previous conflict, after you resolve the current conflict and do 2.如果您没有保留C8中的“依赖”上一次冲突中C3的更改,则在解决当前冲突后

git rebase --continue

you'll get 你会得到

C1---C2---C5---C6---C8'---C9'  master, client
                             \         
                              C3'---C4'---C10' server

Which means that when there are changes on <branch> "depending" on <upstream> that conflict with <newbase> when rebasing, git provides you the merge resolution mechanism as a way to choose if you want those changes now or later. 这意味着当<branch>上的更改依赖于<upstream><newbase>在重新<newbase>时发生冲突时,git会为您提供合并解析机制,以便选择是否要现在或稍后进行这些更改。

My doubt is, what if my changes in client branch were depending on C3 commit in server branch. 我怀疑的是,如果客户端分支中的更改取决于服务器分支中的C3提交,该怎么办? The resultant code in master branch would certainly fail in such a scenario as rebase does 主分支中的结果代码肯定会在rebase这样的场景中失败

That's right. 那就对了。 You've explicitly sliced commit C3 out of your rebased history. 您已经明确地从提交的历史记录中提交了提交C3。 Why do that? 为什么这样? Just git rebase master client . 只需git rebase master client When you merge server git won't try to apply the C3 changes again because they won't show up in the diffs (or alternately further changes to those lines will conflict). 当您合并server git不会再尝试应用C3更改,因为它们不会显示在差异中(或者对这些行的进一步更改会发生冲突)。

edit: comoits aren't "on" branches. 编辑:comoits不是“on”分支。 The history matters. 历史很重要。 The branch names are just lightweight ("throwaway" wouldn't be such a bad word here) references to help identify the commits that interest you. 分支名称只是轻量级(“一次性使用”在这里不会是一个坏词)引用有助于识别您感兴趣的提交。 Focus on the commtts themselves and their ancestry. 专注于自己和他们的祖先。

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

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