7

I have two "branches", both of which started from the same code base, but both of which were imported to git after they diverged. The prior history is lost, and additionally both branches have extensive changes recorded in their git history.

What is a good strategy to approach merging features and bugfixes between these two branches in a manageable way?

Is there a tool that will assist me in separating differences in the original imports into meaningful commits?

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
fuzzyTew
  • 3,511
  • 29
  • 24
  • When you say prior history lost, do you mean that there's no existing copy of the source from before these two repositories/"branches" were created? – Cascabel Jan 26 '11 at 18:01
  • Also, what's the scope of the merging you're trying to do? Recombine the two into one, and go from there with a normal workflow? Continue separately, and cherry-pick things now and then? – Cascabel Jan 26 '11 at 19:21
  • Jefromi, that is correct -- no copy of the prior source. Both repositories will continue to be worked on separately, but I would like to merge (cherry-pick?) the changes of one of them into the other. – fuzzyTew Jan 26 '11 at 22:48

1 Answers1

1

Sounds like you want to keep the history. I would use rebase --onto with --preserve-merges to move features/bugs to the branch you want to continue using. If they sit in a different structure for some reason, make a new branch then do a filter-branch with the tree operation to make the structure the same. Then rebase --onto --preserve-merges as you would in the first scenario.

Hope this helps.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • Thank you for the answer. I'm a bit new to git, so it'll take me a while to read up on those commands and options and see if they can do what I need. Code has moved around inside the files as well as in the directory structure. – fuzzyTew Jan 26 '11 at 22:53
  • 2
    make some copies of the repo and experiment to see what the commands do. I recommend running gitk --all & and refreshing it regularly to see visually what is happening. – Adam Dymitruk Jan 27 '11 at 00:10
  • 1
    Hi, could you please explain your solution a little more? I've read up on the rebase command but i fail to produce a good solution. We have 2 branches which have diverged alot. Now i imported both branches from svn. master and diverged A-B-C-D Master and E-F-G-H Diverged. Now when i branch off master and make 3 commits with changed on that new branch. i want to merge the bugfix branch into master and diverged. Keep in mind that all previous changes from master should be ignored since the source is completly different from diverged. Could you please explain how you would solve this? – Sam Sep 28 '12 at 09:35
  • 1
    You can use `--strategy=ours` or `theirs` to ignore what you merge but still mark it as having been merged. – Adam Dymitruk Oct 01 '12 at 05:17