Tuesday, October 31, 2006

Branching in subversion

Subversion makes branching a simple process. If you set up your repository following the Subversion guidelines, you have a trunk/ directory and a branches/ directory. There's nothing magical about these directories, so if you don't have them, you can put your branch anywhere you like.

You'll use the svn copy command to copy the trunk as a branch. This doesn't actually copy any files until changes are made, so don't worry about disk space.

  1. Decide on a name for the branch. It should be short and descriptive, and usable as a directory name. In these examples, it's "mybranch".
  2. Use the svn copy command to create the branch in the repository by copying the trunk. The arguments are a destination path and a source path. The svn info command may be helpful to remind yourself what your repository path is. Here's an example that creates the mybranch branch from the trunk:
    $ svn copy http://svn.myrepo.com/trunk http://svn.myrepo.com/branches/mybranch
    Committed revision 1701.
    The change is committed immediately. Because this command uses repository paths, it changed the repository directly, with no effect on your working directory.
  3. To get a working directory for your branch, you can simply go to your branches/ working directory and update to get the new branch:
    $ cd /work/branches
    $ svn up
    If you haven't checked out the branches directory, you can use the svn checkout command to get it or just the mybranch directory:
    $ mkdir /work/branches
    $ svn co http://svn.myrepo.com/branches/mybranch

That's it. Now you have a directory at /work/branches/mybranch where you can do whatever work you need to do.

The example above branched from the tip of the trunk (what Subversion calls HEAD). You can also branch from a particular past revision by specifying the -r argument with a revision number.

Working

Working with your branch is exactly the same as working on the trunk. You use svn update to get the latest code from the repository, you edit files, and you use svn commit to check in code to the repository.

Subversion doesn't make any fundamental distinction between branches and trunk. All changesets go into the same list of changesets, each with its own sequential revision number. This is because a Subversion revision number represents a revision of the entire repository, not of a single file.

Get more information

Can't find what you're looking for? Try Google Search!
Google
 
Web eshwar123.blogspot.com

Comments on "Branching in subversion "