Subversion: How to merge a branch back into trunk

Typically, subversion (svn) is used to manage releases. If your latest code is being developed in trunk, for a release, you should create a release branch and then release from a tag created from that release branch. After a period of time, you will probably introduce patches in the release branch and perhaps you might even add additional features to the release branch. At some point, you will probably want to merge your changes back into the trunk. The follow are some steps to merging your changes back into trunk using the command line version of subversion (svn).

1. Step into the release branch and find out what has changed since you created the release branch.
svn log --stop-on-copy

2. Once you have discovered the revision number from the creation date of the release branch (e.g., 999), use this revision number to merge the branch to the trunk. Step into the trunk and execute:
svn merge -r999:HEAD .
The dot at the end indicates your current “trunk” working directory as your target. “HEAD” means the latest revision.

3. Once you have merged the branch into the trunk, then you can commit the changed code to the trunk.
svn ci -m "Merged the branch code changes from revision 999 into trunk."
If there are conflicts, you will have to edit the code and resolve the conflicts. You can use “svn resolved” to clean up the conflict files. Then use “svn ci” or “svn commit” to try again.

Leave a Reply