How can I extract a subtree from my SVN repository into a new one?
-
05-09-2019 - |
Question
We have a Subversion repository with one directory that is:
- Not really in need of revision control beyond the capabilities of RCS
- Not versioned in conjunction with anything else in the repository
- Modified about six times as often as the rest of the repository
Although I know that high revision numbers aren't a problem, nonetheless I'd like to pull this one single directory out of my main repository and into a second, ideally new one.
What is the best process for that? If it makes a difference, the SVN repository is hosted on a (... checks... ) FreeBSD machine.
It's worth noting that while I need to retain the version history in the new repository, there's no need to obliterate the content in the old; it can just sit there, for all I care.
Solution
You could use svnadmin dump and svnadmin load to create a new repository from the original one; then copy the directory that doesn't really fit into your scheme to a better location, then delete everything else. In the original repository you would simply delete the non-fitting directory. This keeps all history intact, and you end up with two repositories.
There is probably a way to subsequently clean both repositories from the then useless parts of the history (svndumpfilter), but since hard disc space is quite cheap I wouldn't think this necessary. Anyway, the SVN documentation has all the information about it.
OTHER TIPS
The recommended way to do this is to use svnadmin dump
, then filter the dump file with the svndumpfilter
tool (see svnbook).
For example, I had a repo with a top-level directory named 'Model', which I wanted to move to its own repo:
svnadmin dump my_orig_repo | svndumpfilter include --drop-empty-revs --renumber-revs Model >model_only.svndump
svnadmin load my_model_repo < model_only.svndump
That creates the new repo with only the Model subdirectory.
For removing it from the original repository, you can simply do an svn rm
. This will remove it from the latest version of the repo, and is the simplest way.
But if the Model directory from my example was very large, maybe I would have wanted to remove it entirely from the original. I could do that by repeating the process to create another filtered svn dump file that excluded it instead. Then I would replace the original with the new one that did not have the excluded directory.
I would export (not checkout) the directory, import it into the new repository, then delete it from the original (with a log message indicating where it went, of course ;-).
That may or may not be the "best" way to do it...
I don't know if I understand this correctly, but there's a nice solution to that. If your original repository was at svn://domain, and the folder you use a lot is called "folder", I believe you can simply perform the following command: svn co svn://domain/folder
to checkout only that folder.