For projects that have a large number of contributors, it’s common for most people to have working copies of the trunk. Whenever someone needs to make a long-running change that is likely to disrupt the trunk, a standard procedure is to create a private branch and commit changes there until all the work is complete.
Merge Syntax:
If you choose to use the svn merge command in all its full glory by giving it specific revision ranges to duplicate, the command takes three main arguments:
- An initial repository tree (often called the left side of the comparison)
- A final repository tree (often called the right side of the comparison)
- A working copy to accept the differences as local changes (often called the target of the merge)
Here are some examples:
$ svn merge http://svn.example.com/repos/branch1@150 \ http://svn.example.com/repos/branch2@212 \ my-working-copy $ svn merge -r 100:200 http://svn.example.com/repos/trunk my-working-copy $ svn merge -r 100:200 http://svn.example.com/repos/trunk
In the examples that follow, i am assuming that your using Subversion and terminal.
Merge a Branch into Trunk
- Check out a copy of trunk:
svn co svn://server/path/to/trunk
- Check out a copy of the branch you are going to merge:
svn co svn://server/path/to/branch/myBranch
- Change your current working directory to “myBranch”
- Find the revision “myBranch” began at:
svn log --stop-on-copy
This should display back to you the changes that have been made back to the point the branch was cut. Remember that number (should be rXXXX, where XXXX is the revision number).
- Change your current working directory to trunk # Perform an SVN update:
svn up
This will update your copy of trunk to the most recent version, and tell you the revision you are at. Make note of that number as well (should say “At revision YYYY” where YYYY is the second number you need to remember).
- Now we can perform an SVN merge:
svn merge -rXXXX:YYYY svn://server/path/to/branch/myBranch
This will put all updates into your current working directory for trunk.
- Resolve any conflicts that arose during the merge
- Check in the results:
svn ci -m "MERGE myProject myBranch [XXXX]:[YYYY] into trunk"
That is it. You have now merged “myBranch” with trunk.
Note: Steps 2-4 can be replaced by a remote log lookup:
svn log --stop-on-copy svn+ssh://server/path/to/branch
Bonus: Cutting a Branch
Cutting a branch is a lot easier than merging a branch. And as an added bonus, I will tell you how.
- Perform an SVN copy:
svn copy svn://server/path/to/trunk svn://server/path/to/branch/newBranch -m "Cut branch: newBranch"
That’s all there is to it.
Merge Tracking
Subversion 1.5 introduced the merge tracking feature to Subversion. Prior to this feature keeping track of merges required cumbersome manual procedures or the use of external tools.
Credit to SVNbook.red-bean.com for the Detailed documentation