Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly merge between branches, branched from different versions of trunk?

Our team uses Eclipse to develop a software product, and recently we switched to Subversion to do our source control/version management. At first our team was still committing directly to the trunk as we were new to Subversion's way of source control and things needed to be drawn out still.

At some point I made my first real branch from the trunk to do development for a specific project within our product. Suppose the branch is called DEV_PROJ.

Later as our team knew better how to work with Subversion from Eclipse, I put the team on our first real development branch, not for a specific sub-project but to keep track of different versions. Suppose the branch is called DEV_VERS. Now we are working on that branch and no longer committing directly to the trunk. DEV_VERS was branched from the latest version of the trunk and there have been no commits to the trunk since then.

In between the two branches about two/three months passed and there have been a lot of changes to the trunk before I made the version branch. Now the time has come for me to merge the changes from DEV_PROJ to the DEV_VERS branch to incorporate the project in our new version branch.

What I did first was merge the latest version of the trunk to my DEV_PROJ branch (forward merge?), thinking that would minimize the difference between the two branches while keeping the changes specific to the project.

What I'm trying now and what I'm having problems with is merging the DEV_PROJ to the DEV_VERS branch. Right-click, Team/Merge my DEV_VERS project to start the merge, there are three tabs to choose from: URL, 2 URLs, Reintegrate. As far as I know this is not a reintegration merge, that would be from branch toward the trunk and not between branches that are not directly related. I also don't need to merge two branches towards my branch so I skip 2 URLs tab.

So I choose the first one, URL. As the source I take my project from the DEV_PROJ branch, Revisions: Start from copy, Depth: Working Copy. In a second try, I also chose to Ignore Ancestry. Both tries I push the Preview button to get an overview of what files are target for merging.

What I see is that there are a lot of files that are candidate for merging, that have not been changed in my DEV_PROJ branch. So the (subversion) merging process sees a lot more merging candidates than I had expected. The files I added to the DEV_PROJ branch appear as "Added", but a whole lot of files that I know I didn't change in that branch appear as "Modified" or "Tree Conflict" in the merge overview.

My questions:

  1. Is this the right way to merge between branches? If not can it be done directly using the merge menu (URL, 2URLs, Reintegrate)?
  2. Is my first step (forward merge trunk to DEV_PROJ) the reason why there are merge candidates that were not supposed to be there?
  3. If there is no direct way of merging these branches correctly, then I only see one option. That is merge the DEV_PROJ to the trunk (reintegrate), and then merge the trunk towards the DEV_VERS branch (forward merge). Would this be the right way to do this? If so, is it the only way to do this?

Eclipse: Helios Service Release 2, build: 20110218-0911
SVN server: 1.6.15
Eclipse SVN plugin: SVNKit 1.3.2 (2.2.2.I20100512-1900) // SVN Connector (2.2.2.I20100512-1900) // SVN Team Provider (0.7.9.I20100512-1900)

like image 963
TT. Avatar asked May 18 '11 12:05

TT.


1 Answers

If I understand your question correctly, this is the state of your project:

        _________________ B        DEV_PROJ
       / 
    A /
---------------------------------- trunk
             C \
                \_____________ D   DEV_VERS

And you want all changes from A -> B in your DEV_VERS branch.

If so, what I would do is the following (the following is the command line equivalent, but it should be easy to find the Eclipse SVN GUI equivalent):

  1. Find the revision of A:

    • svn log --stop-on-copy URL_OF_DEV_PROJ
    • The earliest commit revision number is the revision number of point A
  2. Find the revision of B:

    • Assuming you want to merge all changes in the DEV_PROJ branch, the value of B is simply HEAD
  3. Checkout DEV_VERS:

    • svn co URL_OF_DEV_VERS
  4. Inside the directory of the checked out code from step 3, merge the changes from A to B as follows:

    • svn merge -r<RevisionOfA>:HEAD URL_OF_DEV_PROJ .

In short, what you're doing is taking the difference between A and B and merging it to DEV_VERS

like image 85
ryanprayogo Avatar answered Nov 09 '22 16:11

ryanprayogo