Reorganizing a Subversion Repository to Fit the Trunk-Branches-Tags Convention
Background
In my case I set up my project’s repository when I was very new to Subversion. Rather than try to figure out the why’s and how’s of using the conventional directory structure of repository-for-project/trunk and repository-for-project/branches I decided to go bare bones. I ended up with my project’s trunk code essentially living in repository-for-project/.
Now that I’m approaching the first release of the project’s code, I have a better understanding of Subversion’s implementation of branching, and I need to move repository to some place publically accessible, I’ve decided to switch to the trunk/branches/tags convention that so many other project’s use.
Dump the existing repository:
As outlined in a post in Scott Sanders blog, I started by creating a dump file of my current repository:
$ svnadmin dump /path/to/old/repository > old_repository.dump
If the new repository is on a different host, do the following:
$ scp old_repository.tgz hostname:/path/to/parent/directory/for/new/repository/
Setup the new repository:
On the host that is going to be the home of the new repository:
$ svnadmin create new_repository
If you moved the old repository dump file by way of a tarball…
Now we have to setup the three directories in our new repository. We’ll need a checkout from our new repository to do this. See here for a more indepth tutorial on this, but we do it like so:
$ cd tmp
$ svn co file:///path/to/new/repository checkout-tmp # “co” is shorthand for checkout
$ cd checkout-tmp
$ mkdir branches
$ mkdir tags
$ mkdir trunk
$ svn add trunk tags branches
$ svn ci -m “adding top level directories” # “ci” is shorthand for commit and -m passes a log message
$ cd ../../
$ rm -rf tmp
Here comes the cool part. We can load our old repository with all it history into the new repository, but under trunk with one command:
That’s it, for new checkouts just specify the new repository and you are good to go. However, if you have an old working checkout, you’ll probably want to move it aside, do a new checkout, and copy anything appropriate to the new checkout.
Enjoy,
Walter

