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
Cis 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
rebasingJust rebase everything between
topicandrebasingontotopic.or do the same with a shorter command
Now when we just look at
rebasingwe have a straight line formAtoD.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, if you want to.--interactive
Or you rebase everything in a slightly more complicated way. Let’s start again.
First take everything from
Cto the tip ofmaster(aka.D) and put it on thetip of
topic(aka.H) :One last rebase, at the end, and we are finished.
Voila!