Math-Linux.com

Knowledge base dedicated to Linux and applied mathematics.

Home > Linux > Tip of the day > SVN — Branch, Branching subversion howto

SVN — Branch, Branching subversion howto

Requirements

I suppose here your server is based on svn over ssh (svn+ssh), you can
easily replace svn+ssh by https if you use Webdav for example.

svn+ssh://your/server/...
https://your/server/...

Creating the branch

Choose a branche name for example, MyBranch. Create the branch in the repository by copying the trunk:

$ svn copy svn+ssh://your/server/trunk svn+ssh://your/server/branches/MyBranch
Committed revision 3328.

Remember this commited revision number 3328.

If you have a local copy you do not need to checkout your branch just switch:

$ cd /your/local/copy
$ svn switch svn+ssh://your/server/branches/MyBranch .

Do not forget the dot at endline.

If you do not have a local copy you, checkout your branch:

$ mkdir /your/local/copy
$ cd /your/local/copy
$ svn checkout svn+ssh://your/server/branches/MyBranch .

Check if the localization is ok:

$ svn info | grep MyBranch
URL: svn+ssh://your/server/branches/MyBranch

Now you can work with your branch exactly as working on the trunk. (update, commit, etc ...).

Merge with the trunk

You’ve been developing on your branch, and so have other people on trunk, and now you have to add their changes to your branch.

$ cd /your/local/copy
$ svn update
At revision 3269.

Add their changes to your branch:

$ svn merge -r3328:3269 svn+ssh://your/server/trunk .
U    src/file.cpp
U    src/file.h

This command finds all the changes in revisions 3329, 3330, ... , 3269 that were made in the trunk, and applies them in Mybranch.

Now you must commit these changes to your branch repository; with appropriate comments to remember which range you have already merged:

$ svn ci -m "Merged the trunk from 3328 to 3269." .
Sending        src/file.cpp
Sending        src/file.h
Transmitting file data ..
Committed revision 3270.

After another interval of work, you will have to merge again to get the new changes.
You specify a revision range that takes only the changes you haven’t already merged:

$ cd /your/local/copy
$ svn update
At revision 3333.

Add their changes to your branch:

$ svn merge -r3269:3333 svn+ssh://your/server/trunk .
U    src/file.cpp
U    src/file.h

This command finds all the changes in revisions 3370, 3371, ... , 3333 that were made in the trunk, and applies them in Mybranch.

Now you must commit these changes to your branch repository:

$ svn ci -m "Merged the trunk from 3269 to 3333." .
Sending        src/file.cpp
Sending        src/file.h
Transmitting file data ..
Committed revision 3334.

}

Back to the trunk

Once you have finished your branch and you have merged again the last change from the trunk, you
will commit your branch back to the trunk. Remember! MyBranch was created at revision number 3328.
Now you have to add all your changes to the trunk.

$ cd /your/local/copy
$ svn update
At revision 3400.

Switch to the trunk and merge from Mybranch all the changes(3328:3400) to the trunk

$ svn switch svn+ssh://your/server/trunk

Check if the relocalization is ok:

$ svn info | grep MyBranch
URL: svn+ssh://your/server/trunk

Add all your changes to the trunk

$ svn merge -r3328:3400 svn+ssh://your/server/branches/MyBranch .

Now you must commit these changes to the trunk:

$ svn ci -m "branch back MyBranch into trunk" .
Sending        src/file.cpp
Sending        src/file.h
Transmitting file data ..
Committed revision 3334.

Delete your branch

At last, delete your branch

svn del svn+ssh://your/server/branches/MyBranch

Any message or comments?

comments powered by Disqus