A ...">

Combining merged branch history in GIT?

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

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

      

Now I want to merge the branches to get the following history:

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

      

How can i do this?

Regards, Jochen

+2


source to share


2 answers


I am assuming that C

is a merge commit and that is the reason why you do not want to have it in your result.

What you need to do what you want is git rebase

Let's start with another commit graph. To keep the original branch, we will work on a new branch namedrebasing

git checkout -b rebasing master

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

      

Just reinstall everything between topic

and rebasing

on 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 that we just look at rebasing

, we have a straight shape A

before 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 can easily fix this by reordering the commits with git rebase --interactive

if you like.

Or you reinstall everything is a little more complicated. Start over again.

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

      

First take everything from C

to the end master

(aka. D

) And put it on tip 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 move at the end and we're done.

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)

      

+6


source


I would separate from A and then cherry pick on the entries you want

So:



git checkout -b my-branch A
git cherry-pick B
git cherry-pick F
git cherry-pick G
git cherry-pick H
git cherry-pick D

      

+1


source







All Articles