How to merge on subversion

In this post we will show how to do a merge between a branch and the trunk.

In a previous post we saw how to use subversion from the command line to manage our project repositories, now we will see how to do merge from a branch to a trunk.

We use branches for new features to be developed, while the trunk is normally used as the main development thread. To do a merge we should use the following commands:

1. Check out a copy of the trunk:

1
user@unix:~$ svn co https://svn.hasheado.com/myProject/trunk

2. Now, we do a check out of the branch we want to merge:

1
user@unix:~$ svn co https://svn.hasheado.com/myProject/branches/1.0.1

3. We should change the work copy to the last branch and find in what revision we are:

1
2
user@unix:~$ cd /path/to/branches/1.0.1
user@unix:~$ svn log --stop-on-copy

This last command should show us the changes those did made since the creation branch. Take note of that number (should be in the way of rXXX, where XXX is the revision number).

4. Change our work copy to the trunk and do an update:

1
2
user@unix:~$ cd /path/to/trunk
user@unix:~$ svn update

That update will update our work copy to the most recient revision, and it will tell us what revision is. We should take note of this revision number (“at revision YYY”).

5. Now, we could simulate the merge:

1
user@unix:~$ svn merge --dry-run -r XXX:YYY https://svn.hasheado.com/myProject/branches/1.0.1

The –dry-run option simulates the merge, but it does not make it, in that way we can see what files will be merged and if we should resolve some conflicts.

6. After review the simulation output, we should do the merge:

1
user@unix:~$ svn merge -r XXX:YYY https://svn.hasheado.com/myProject/branches/1.0.1

7. And at the end, do a commit to the repository:

1
user@unix:~$ svn ci -m "MERGE myProject from branch 1.0.1"

That is all, the merge is done.

NOTE: Take in account that the url used are just samples.