next up previous contents
Next: Creating tags Up: Tags and Branches Previous: Retrieving a branch   Contents

Merging branches

When two branches are developed, we have to be able to move some changes like bugfixes from one branch to another. This feature is provided by svn merge command.

We are going to do some parallel changes to br-0.8 and to the trunk and we will merge br-0.8 to trunk.

$ svn info
Path: .
URL: https://localhost/svn/repo1/helloworld/branches/br-0.8
$ echo "Documentation for the project" > docs/docs.txt
$ mkdir docs/site
$ mkdir docs/qa
$ echo "Index Page" > docs/site/index.html
$ svn add docs/site docs/docs.txt
$ svn commit -m "added docs"

Now we have added a file docs/docs.txt, an index page for the project's site docs/site/index.html and an empty directory docs/qa in br-0.8

If we want to preview the differences between br-0.8 and trunk, we may want to use svn diff, but it is not sufficient, because it shows onlu the changed files and not the changed directories. In our case it does not show that docs/qa directory is created in br-0.8. The most appropriate way to preview the changed elements is with svn merge command itself and its -dry-run option. The command accepts three arguments: the initial branch (to which we merge), the final branch (from which we merge) and a working copy that will accumulate the differences as local modification. When we are happy with the merge we commit that working copy.

In our case, since we merge from br-0.8 to trunk we will need a local copy of trunk in order to commit the changes to trunk. So we switch to trunk:

$ svn switch https://localhost/svn/repo1/helloworld/trunk

Then we construct the merge command - the initial branch is trunk, the final branch is br-0.8

$ svn merge --dry-run
      https://localhost/svn/repo1/helloworld/trunk
      https://localhost/svn/repo1/helloworld/branches/br-0.8
A    docs/qa
A    docs/site
A    docs/site/index.html
A    docs/docs.txt

The changed files and directories are listed and if we like the result, we can start the actual merge by removing -dry-run.

$ svn https://localhost/svn/repo1/helloworld/trunk
      https://localhost/svn/repo1/helloworld/branches/br-0.8
A    docs/qa
A    docs/site
A    docs/site/index.html
A    docs/docs.txt

When we do not provide the argument for the working copy, it is assumed that the current directory contains the working copy. After we merged the two branches, we can preview the exact changes applied in the local copy:

$ svn status
A  +   docs/qa
A  +   docs/site
A  +   docs/site/index.html
A  +   docs/docs.txt
$ svn diff

After we adjust the changes we can commit them. It is impportant to provide a meaningfull log message for this commit, because Subversion does not remember its merges:

$ svn commit -m "merge from br-0.8 to trunk"


next up previous contents
Next: Creating tags Up: Tags and Branches Previous: Retrieving a branch   Contents
Ivan Ivanov 2008-04-21