在GIT中合并分支机构的历史? [英] Combining history of merged branches in GIT?

查看:173
本文介绍了在GIT中合并分支机构的历史?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 在我的git仓库中,我将分支B合并到master中, - > A  - > B  - > C  - > D(分行主)
| |
F - > G - > H(分支B)

我现在想要组合分支以获得以下历史记录:

   - > A  - > B  - > F  - > G  - > H  - > D 

我该怎么做?

问候,
Jochen

解决方案

我假设 C 是一个合并提交,这就是你不想在你的结果中得到它的原因。



你需要做什么,做你想做的是 git rebase



让我们从另一个原理图提交图开始。要保留原来的
分行,我们将在一个名为 rebasing

的新分行上进行操作。  git checkout -b rebasing master 

- > A - > B ------------------- - > C - > D(分行主)(分行重新分配)
\ /
+ ---- + - > F - > G - > H - +(分支主题)

只需重新设定主题重新装订主题

  git rebase --onto topic topic rebasing 

或者做同样的事情使用较短的命令

  git rebase topic 

- > A - > B -----------------> C - > D(分行主)
\ /
+ --- +> F - > G - > H +(分支主题)
\
+ ---------> B - > D(分行重新发放)

现在当我们看看 rebasing 我们有一条直线形式 A D

   - > A  - > F  - > G  - > H  - > B  - > D(分支重定)

所以,现在唯一的问题可能是订单与
您的预期。如果你愿意的话,你可以通过对 git rebase
--interactive
进行重新排序来轻松解决这个问题。



<或者你以一种更复杂的方式重新设定一切。让我们再次开始。

   - > A  - > B -------------------  - > C  - > D(分行主)(分行重新分配)
\ /
+ ---- + - > F - > G - > H - +(分支主题)

首先从 C master (aka。 D >)的小费,并将其放在
小费主题(aka。 H ):


  git rebase --onto topic C master 

- > A - > B ----------------> C - > D(分支主人)
\ /
+ ----> F - > G - > H +(分支主题)
\
+ ---------> D(分行重新贷款)

最后一次转账,最后我们完成了。

  git rebase B 

+ ----> F - > G - > H +(分支主题)
/ \
- > A - > B ----------------> C - > D(分行主)
\
+ ------------------------> F - > G - > H - > D(分行重新贷款)

Voila!

   - > A  - > B  - > F  - > G  - > H  - > D(分行重新贷款)


In my git repository, I have merged branch "B" into "master", getting the the following structure:

--> A --> B --> C --> D  (branch master)
    |           |  
    F --> G --> H        (branch B)

I now want to combine the branches to get the following history:

--> A --> B --> F --> G --> H --> D

How can I do this?

Regards, Jochen

解决方案

I assume C is a merge commit, and that's the reason you don't want to have it in your result.

What you need, to do what you want, is git rebase

Let's start of with yet another schematic commit graph. To leave the original branches intact we will operate on a new branch called rebasing

git checkout -b rebasing master

--> A --> B------------------- --> C --> D         (branch master) (branch rebasing)
     \                           /
      +----+->  F --> G --> H -+                   (branch topic)

Just rebase everything between topic and rebasing onto topic.

git rebase --onto topic topic rebasing

or do the same with a shorter command

git rebase topic

-> A -> B -----------------> C -> D                (branch master)
    \                      /
     +---+>  F -> G -> H +                         (branch topic)
                          \
                           +---------> B -> D      (branch rebasing)

Now when we just look at rebasing we have a straight line form A to D.

-> A -> F -> G -> H -> B -> D                      (branch rebasing)

So, the only problem right now might be that the order is different from what you expected. You could easily fix that by reordering commits with git rebase --interactive, if you want to.

Or you rebase everything in a slightly more complicated way. Let's start again.

--> A --> B------------------- --> C --> D         (branch master) (branch rebasing)
     \                           /
      +----+->  F --> G --> H -+                   (branch topic)

First take everything from C to the tip of master (aka. D) and put it on the tip of topic (aka. H) :

git rebase --onto topic C master

-> A -> B ----------------> C -> D                (branch master)
    \                      /
     +----> F -> G -> H +                         (branch topic)
                          \
                           +---------> D           (branch rebasing)

One last rebase, at the end, and we are finished.

git rebase B

     +----> F -> G -> H +                         (branch topic)
    /                     \
-> A -> B ----------------> C -> D                (branch master)
         \
          +------------------------> F -> G -> H -> D   (branch rebasing)

Voila!

-> A -> B -> F -> G -> H -> D                      (branch rebasing)

这篇关于在GIT中合并分支机构的历史?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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