Search code examples
svnmergesvn-merge

merge 2 svn branches together


I'm working with an svn setup I'm not used to and I need to merge new code from one branch to another.

There's no code in the trunk folder so I don't know if I should update the trunk to the code and update the second branch, OR if there is a way to just update one branch to the other. My last resort is going to be just updating the code manually.

Any ideas what the best route here is? I'm doing everything from a terminal.


Solution

  • No Don't update manually. Of course the difficulty will depend on how close those branches are.

    You can always bring changes from a branch to another branch. Let's say you have two branch named branch1 and branch2 and you want to merge branch2 to branch1.

    Say you are in branch1 (Try the dry run first to see if it results in conflicts)

    svn merge -r LAST_MERGED_REVISION:HEAD_REVISION --dry-run url/to/branches/branch2 .
    
    svn merge -r LAST_MERGED_REVISION:HEAD_REVISION url/to/branches/branch2 .
    svn status | egrep '^C|^.C' <---Manual intervention is required for conflicts
    svn update
    svn ci -m "Merge changes from branch2"
    

    And you can close out branch2

    svn merge --reintegrate url/to/branches/branch2
    svn update
    svn ci -m "Merged branch2 to branch1"
    

    This may fail in case the branches are very divergent.