Extracting a Directory into its Own Subversion Repository @ r2

This article was originally published in my blog (affectionately referred to as blargh) on . The original blog no longer exists as I've migrated everything to this wiki.

The original URL of this post was at https://tmont.com/blargh/2009/10/extracting-a-directory-into-its-own-subversion-repository. Hopefully that link redirects back to this page.

Like my previous subversion post, this is something that is a bit difficult to find on the internet.

Every so often, you realize that a project is growing too big, and it deserves its own repository. What you want is to extract a single directory from one repository, and create an entirely new repository that only has the revisions related to that one directory in it. And it would be nice if they started from one. Luckily, subversion provides just such a tool for doing it.

Suppose your repo looks like this:

plaintext
/foo
/bar
--/src
--/tests
--/www
----/css
----/images
----/js
--/bin
/baz
/bat

and you want to remove the "bar" directory and create a new repository out of it. Here is what you would do:

bash
svnadmin dump /path/to/big/repo > repodump
cat repodump | svndumpfilter include bar --drop-empty-revs --renumber-revs > newrepodump
svnadmin create newrepo
svnadmin load newrepo > newrepodump

You'll probably want to create trunk, tags and branches for your new repo, so you have two choices:

  1. Try and figure out how to modify the dump file and delete the proper nodes (impossible)
  2. Say screw it, and just svn mv the files around after you've loaded the revision into the new repo

This is all fine until you realize that svndumpfilterdoesn't play nice with an svn mv outside of the directory you're filtering. That's when you have to play with the exclude subcommand, and pipe the output about 30 different times to svndumpfilter until you've got what you want. It's not enjoyable. I'll leave this one as an exercise to the reader.