sonia hamilton – life on the digital bikepath – sonia@snowfrog.net

24 February 2009

Notes on Branch Management with Subversion

Filed under: Subversion — Sonia @ 17:08

Some notes on branch management with Subversion (more for my own learning purposes than anything):

  • create branch: svn cp foo foo-branch
  • develop new feature in foo-branch, whilst doing any bug fixes in trunk
  • merge some changes from trunk into branch – keep branch up-to-date as possible
    • commit any changes first, so can easily revert if desired: cd foo-branch; svn up; svn ci -m “pre merge in trunk”
    • find where branch occured (if not noted in a log message – duh): svn log –verbose –stop-on-copy foo-branch (eg 123)
    • preview changes succinctly: cd foo-branch; svn merge –dry-run -r 123:HEAD
    • preview changes verbosely: cd foo-branch; svn diff –notice-ancestry -r 123:HEAD …
    • apply changes: cd foo-branch; svn merge -r 123:HEAD svn+ssh://myrepo.com/foo/bar
    • check changes: svn st; svn diff, if problems: svn revert
    • commit changes: svn ci -m “merged trunk changes into branch (flubbed the widgets) r123:129″
  • keep working in foo-branch, merge in some more changes
    • ditto previous
    • svn merge -r 130:HEAD svn+ssh://myrepo.com/foo/bar (previously merged up to 129, so start on 130)
  • merge all changes from branch into trunk – new feature finished
    • ditto previous
    • cd foo; svn merge -r 123:HEAD https://myrepo.com/foo-branch
    • svn ci -m “merged foo-branch into trunk (feature x) r123:145″

An alternative (and often easier) approach is to branch on the server, then just switch the working copy for the subdirectory (or individual file) being worked on:

  • svn cp https://myrepo.com/foo https://myrepo.com/foo-branch
  • cd foo
  • svn info bar | grep URL
  • cd bar; svn switch https://myrepo.com/foo-branch/bar; cd ..
  • svn info bar | grep URL
  • merge changes as above

Tags:

  • tags are just copies (usually put in the tags directory): svn cp https://myrepo.com/foo/foo https://myrepo.com/foo/tags/foo-1.0. Tags aren’t read-only, but any changes can of course be reverted.

Directory structure:

  • the canonical way of structuring directories is:
    • /foo/trunk (or /foo/foo so name of trunk dir corresponds to project when checked out)
    • /foo/branches
    • /foo/tags
  • I used to ignore this and just do /foo & /foo-branch, but this gets messy quickly and it’s easy to make mistakes or have problems when doing svn moves of  large directories if you want to reorganise things later. Also, when working with branches I tend to want to just switch a subdirectory rather than checkout the whole branch, and this directory structure seems to logically help with this

Notes from Version Control with Subversion.

2 Comments »

  1. Hi Sonia,

    Thanks for sharing your thoughts.

    Regarding this:

    merge all changes from branch into trunk – new feature finished

    * ditto previous
    * cd foo; svn merge -r 123:HEAD https://myrepo.com/foo-branch
    * svn ci -m “merged foo-branch into trunk (feature x) r123:145″

    is “https://myrepo.com/foo-branch” supposed to be https://myrepo.com/foo/trunk ?

    Comment by Slavi — 24 April 2009 @ 03:44

  2. Hi Slavi, thank you for your comments.

    I’m having a few days off – let me check your correction when I get back :-)

    Comment by Sonia — 24 April 2009 @ 13:02


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.