0

I have recently migrated my SVN repo to GIT. The SVN repository had 2 branches with same commit history. Now in GIT , I would like to have these 2 branches with parallel graph have a common root. How can I do it? Rebasing one branch over other doesn't works.

$ git checkout BRANCH_1
$ git rebase BRANCH_2

This gave me an error of unrelated histories.

$ git rebase BRANCH_2 --allow-unrelated-histories

did not joined the two branches at the commit they were supposed too.

dgupta3091
  • 1,067
  • 1
  • 7
  • 18
  • 2
    I suppose you could create a third branch with a single commit in it that contains the source code state which you envision as your root. (That could possibly be an empty source tree if there is no real logical root.) Then you'd rebase both your branches *on that third branch*, i.e make that single commit the first commit in each branch (and re-write their complete history). – Peter - Reinstate Monica Aug 08 '19 at 13:46
  • If they have the same commit history, they have the same root as well, right? Anyways, rebasing both branches to the same commit should work. – mfnx Aug 08 '19 at 13:52
  • 1
    Please, expand on rebasing one branch over the other doesn't work. – mfnx Aug 08 '19 at 13:53

1 Answers1

0

following worked for me..

Supposedly, the two branches are BRANCH_1 BRANCH_2

$ git checkout BRANCH_1

I checked out to the commit from where I needed the common root

$ git checkout e405d8d172dfa017a3fea17ce111dff280412a3c

Then I created a new branch from current commit and checked it out

$ git branch NEW_BRANCH
$ git checkout branches/release/0.0.1

Then I cherry picked the commit which I wanted from BRANCH_2

$ git cherry-pick 47c661bfb8cbf79017bff53fedbbd7db13cf68bf
$ git push --set-upstream origin NEW_BRANCH
$ git branch -D BRANCH_2

Note: I could delete BRANCH_2 because I had the same history for both branches. i.e.

$ git diff 47c661bfb8cbf79017bff53fedbbd7db13cf68bf e405d8d172dfa017a3fea17ce111dff280412a3c

returned empty

dgupta3091
  • 1,067
  • 1
  • 7
  • 18