1

After having a look at a gazillions of websites and StackExchange questions, I want to add a further question about Git. I think that this answer comes quite close to what I want, but I was not successful.

Gitg displays my repository as having branches (ok), but one of these branches was merged into another one twice. I want to modify the history by just removing the commits which do these merges. These commits have a message beginning with "Merge branches" and "Merge branch". All I want is to just keep these branches parallel, unmerged. Also, there were commits to these branches after these merges which have to be kept intact. These branches do not touch the same files, so there should not be a conflict.

Please see here the screenshot of Gitg. So, I want these branch drawn in blue not connect to the branch drawn in green. How can I do this (for manipulating the repository, I am using the command line, of course).

Gitg showing merged branches

rexkogitans
  • 279
  • 2
  • 17

1 Answers1

0

If the history after those merges is a straight line, you can try this:

git checkout revision-before-first-merge
git cherry-pick id-of-second-merge..the-branch
# now you have a history like what you want
# if you like how it looks, then it's time to move the branch
git branch -f the-branch # set the branch over here
git checkout the-branch

Warning: this is rewriting history of this branch which is technically possible (as we just saw) but it has implications.

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • Could you please clarify what you mean by `the-branch` and `revision-before-first-merge` (is this the ID of the node in the blue strand)? – rexkogitans May 18 '21 at 08:10
  • I don't think so. The blue strand is the branch you would like to separate, right? Then it's the parent (on the blue branch) of the first merge. – eftshift0 May 18 '21 at 13:32