Search code examples
eclipsesvnversion-controlsubversive

How to merge the changes in a branch to the trunk


I'm new in working with branches in SVN and I'm having a problem (maybe is a concept issue) I can't understand when trying to merge the changes of a branch into the trunk.

I will develop a full example in order to explain the full problem. I'm working with Eclipse/Android and Subversive:

I created a new project with the structure shown in the Picture 1 and commit it as the Revision #1 to https://mysubversionhost/Tests/SVNTests/trunk (ignoring gen and bin folders)

Picture 1:

enter image description here

At this point the MainActivity.java is

package com.example.svntests;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
}

Then I continue working in the project and update the MainActivity.java commiting it as the Revision #2:

package com.example.svntests;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        codeA();
        codeB();
        codeC();
        System.out.println("This is a bug!");
        codeA();
        codeB();
        codeC();
    }

    private void codeA() {
        // CODE A
    }

    private void codeB() {
        // CODE A
    }

    private void codeC() {
        // CODE A
    }

}

At this point I decide to make a release and create a tag name Release1.0. The SVN structure at this point is shown in the Picture 2 (Revision #3)

Picture 2:

enter image description here

Then I continue working in the trunk and removing the calls to codeA() and adding a class OtherActivity.class in the com.example.svntests. Commiting the Revision #4 MainActivity.java at this point is:

package com.example.svntests;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        codeB();
        codeC();
        System.out.println("This is a bug!");
        codeB();
        codeC();
    }

    private void codeB() {
        // CODE A
    }

    private void codeC() {
        // CODE A
    }

}

Then I detect the bug "This is a bug!" and want to patch it in production. So I switch to the tag Release 1.0 and fix it (removing the print line and adding a class MainController.java to the same package) and commit it Revision #5

At this point I want to continue working with the Revision #4 with the bug fixed. So I switch to the trunk and use the merge wizard to bring the changes from the branch to the trunk:

enter image description here

I was expecting to get in my working copy the classes:

- MainActivity.java (With conflicts)
- OtherActivity.java
- MainController.java

But instead I get conflicted files that were not modified. See image below

enter image description here

The final state after the merge is:

enter image description here

What do I am missing?


Solution

  • Well, you have some misunderstanding in SVN common (I'm too lazy to adopt some of it to Eclipse GUI)

    • /tags subtree, by convention, is "write-once" - and all|each tag must not have history of changes inside /tags/. When you want to bugfix some tag, you have (in ideal world):
      • Copy tag to /branches/
      • Patch branch
      • If branch's code went to production - tag branch as new tag (Release 1.1, probably)
    • In order to bring only bugfix changes into trunk from location-of-bugfix, you'll better merge only revisions, related to bugfix, not the whole history ("cherry-pick merge" instead of "sync merge")(choice 3 "Revisions", enter just 5 in your sample)