tags:

views:

50

answers:

3

I've made some experimental code that I would like to save in the repository, but I don't want it on the main branch. How would you commit this to a branch?

Maybe I got this wrong, but of what I've understood about branching, all you actually do is copying already checked in code to another directory in the repository. I suppose one could copy the main branch to another location, and then change the working copy repository location pointer to point at that location, and then commit the experimental code. But that seems a bit long-winded. Is this really how you do it?

+1  A: 

An SVN branch does not copy all the code again, it just refers to the original, and adds the Diff of your new code. Another good thing of a branch is that you can always merge or sync it it back with its source. A branch is just another folder in the SVN Repository like tags or trunk.

I would suggest creating a backup before switching branches, in case you overwrite your existing changes by mistake.

You can find the commands and more information about SVN branches in the free SVN Book

Benjamin Ortuzar
+3  A: 

That is indeed how you do it (at least in Subversion). For example:

svn cp svn://server/repo/trunk svn://server/repo/branches/experiment
svn switch svn://server/repo/branches/experiment
svn commit -m "testing stuff"

The Subversion cp (copy) operation is designed to be very cheap and doesn't actually make a copy of all the code in your repository again. It just sets up pointers to point to the revision you copied from in trunk.

Not all systems work this way; for example in Git you can create a new branch and switch to it with one command: git checkout -b experiment.

Greg Hewgill
+1  A: 

AFAIK most SVN clients with a GUI (e.g. Tortoise, Subclipse, SvnX has a branch command that does the magic for you.

Otherwise see Greg's answer.

lajuette