简体   繁体   English

合并GIT中的大儿童分支

[英]Merging a grand children branch in GIT

I'm in a specific situation and I'd like an opinion before messing up all my branches :-) Currently, I have this architecture : 我处在特定情况下,在把我的所有分支弄乱之前,我想先发表一下意见:-)目前,我有这样的体系结构:

master
   hotfix
   development
      p2

Recently, I had an issue and had to work on the hotfix branch. 最近,我遇到了一个问题,不得不在hotfix分支上工作。 Now it's fixed and I merged it to the master one. 现在它已修复,我将其合并到master Usually, when I deploy something, it's from the development branch, however, due to dramatic schedule modifications, I will have to deploy the p2 branch instead of the development one. 通常,当我部署某些东西时,它来自development分支,但是,由于日程安排的重大修改,我将不得不部署p2分支而不是development分支。 Indeed, the changes in p2 must go live before the one in development (and the one in development can't go before the ones in p2 ). 事实上,在变化p2必须在一个之前走活development (和一个在development的问题之前不能进去p2 )。

Deploying p2 is not an issue, but then I have questions about the next steps. 部署p2并不是问题,但是接下来我对后续步骤有疑问。

  1. Is it possible to merge the master branch with the p2 branch (in order to have the latest changes) without merging into development first? 是否可以将master分支与p2分支合并(以进行最新更改)而无需先合并到development
  2. If 1 is possible, I'd like to merge p2 back into master once the code is deployed, but then, if I try to merge master into development (to put the changes of p2 in development ), will all the changes I made in p2 be included in the merge ? 如果可能为1 ,则我希望在代码部署后将p2合并回master ,但是,如果我尝试将master合并到development (将p2的更改放入development ),我所做的所有更改都将p2是否包含在合并中? I'm afraid that it won't be the case because of the first merge I did with master (as its latest commit has been done way after all the changes in p2 ). 恐怕不是这种情况,因为我与master进行了第一次合并(因为它的最新提交在p2所有更改之后都已完成)。

Thanks 谢谢

Somewhat more detailed answer : 更为详细的答案:

Your starting state is : 您的开始状态是:

# sketch 1 :

*--A--*--*--*--*--*--*--*--* master
    \  \            /
     \   *--*--*--* hotfix
      \
       \
        *--*--B--*--*--* development
               \
                 *--*--*--* p2

You can merge p2 into master : 您可以将p2合并到master中:

# sketch 2 :

*--A--*--*--*--*--*--*--*--*-----* master
    \  \            /           /
     \   *--*--*--* h          /
      \                       /
       \                     /
        *--*--B--*--*--* d  /
               \           /
                 *--*--*--* p2

Once you have done this, git has stored the fact that the B commit (and all of the commits between A..B ) is part of master 's history. 完成此操作后,git存储了以下事实: B提交(以及A..B之间的所有提交)都是master历史记录的一部分。

So later on, when you decide to merge development into master : 因此,稍后,当您决定将开发合并到master中时:

# sketch 3 :

*--A--*--*--*--*--*--*--*--*-----*-----* master
    \  \            /           .     /
     \   *--*--*--* h          .     /
      \                       .     /
       \                     .     /
        *--*--B--*--*--*--*----*--* development
               \           .
                 *--*--*--* p2

it will only look at the differences between B..development (instead of A..development ) 它只会查看B..development之间的B..development (而不是A..development


On these sketches, p2 is drawn below development . 在这些草图上, p2绘制在development之下。

But git does not care about this notion of "below". 但是git不在乎“以下”的概念。

From git's point of view, sketch 2 is the same as : 从git的角度来看, sketch 2与:

# sketch 2':

         *--*--*--*  h
       /            \
*--A--*--*--*--*--*--*--*--*--* master
    \                        /
     \            *--*--*--* p2
      \         /
       \       /
        *--*--B--*--*--* d

And sketch 3' may be clearer in showing how git resolves the new "forking point" between master and development : sketch 3'在显示git如何解决masterdevelopment之间的新“分叉点”时可能更清晰:

# sketch 3':

         *--*--*--*  h
       /            \
*--A--*--*--*--*--*--*--*--*--*------* master
    \                        /      /
     \            *--*--*--*       /
      \         /                 /
       \       /                 /
        *--*--B--*--*--*--*--*--* development

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

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