How can I extract a subtree from my SVN repository into a new one?

*爱你&永不变心* 提交于 2019-12-03 12:52:12

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!