How do I move a single folder from one Subversion repository to another repository?

SvnRepositoryDirectoryMove

Svn Problem Overview


I have a "docs" folder in a Subversion repository named "project". I've come to the conclusion that it should really be kept under a separate Subversion repository named "project_docs".

I'd like to move the "docs" folder (and all of its revisions) to the "project_docs" repository. Is there a way to do this?

Svn Solutions


Solution 1 - Svn

If you have access the repository itself (not a working copy), you should be able to dump the current repository, filter it to only include information about the docs folder, and load it into the other repository.

Would be something like this:

svnadmin dump /svn/old_repos > ./repository.dump
svndumpfilter include path/to/docs --drop-empty-revs --renumber-revs --preserve-revprops < ./repository.dump > ./docs_only.dump
svnadmin load /svn/new_repos < ./docs_only.dump

Without access to the repository, you cannot maintain the revision history and you have to settle for copying the files into the new repository and committing.

Solution 2 - Svn

svndumpfilter has a serious flaw - if a file or path was copied from a path you're filtering out to one you're filtering in, svndumpfilter won't be able to fill out the history and the job will fail.

You can use svndumpfilter2 if you experience this problem.

Solution 3 - Svn

This is discussed in the SVN documentation. Check out the Repository Maintenance section on svndumpfilter... It specifically describes how to dump projects out of a central repository and move them into new, separate repositories.

Solution 4 - Svn

I don't believe you can do it remotely (i.e., without a local copy). But this should work: svn export the folder from the original server, then svn add it to your new repo.

Like:

$ svn checkout svn://example.net/newrepo .
$ svn export svn://example.com/oldrepo/mydir ./mydir
$ svn add ./mydir; svn commit

Edit: D'oh, this drops the history. Use svnadmin as https://stackoverflow.com/questions/417726/how-to-move-a-single-folder-from-one-subversion-repository-to-another-repository#417748">Samuel describes.

Solution 5 - Svn

For future reference:

SVN documentation clearly reports:

If you do plan on manually editing the dump file to remove a top-level directory, make sure your editor is not set to automatically convert end-of-line characters to the native format (e.g., \r\n to \n), as the content will then not agree with the metadata. This will render the dump file useless.

Use sed or Vim to substitute the top-level directory, but this directory name was contained also inside a project file!!!! This causes an SVN load checksum error.

So when you perform this operation, don’t do string substitutions with sed of only the path name.

Substitute “Node-path: old_path” with “Node-path: new_path”. See SVN book chapter 5 “repository administration” for more details.

Solution 6 - Svn

I tried to use the accepted answer, but I had a huge repository and I wanted to export a small directory, and I couldn't afford to dump the entire repository.

So, I only exported the revisions where my directory changed (This may not work if the directory you want to export have references to other places in your repo).

svn log URL_to_docs | awk '/^r/{gsub(/^r/,"",$1);print $1}' > revisions.txt
#tac for revisions in reverse (oldest revision first)
tac revisions.txt | while read line; do svnadmin dump /svn/old_repo -r$line >> ./docs_revisions.dump ; done

#You don't have to filter if you commited only files in your directory docs in your exported revisions
svndumpfilter include path/to/docs --drop-empty-revs --renumber-revs --preserve-revprops < ./docs_revisions.dump > ./docs_only.dump

svnadmin load /svn/new_repos < ./docs_only.dump

You must replace your repo URL (URL_to_docs), location in server (/svn/old_repo) and path to docs in repository (path/to/docs)

You can easily edit your docs_only.dump if you want to change the location of your doc directory in your new repository.

Solution 7 - Svn

I did not have so much success in achieving similar goal with any of the svndumpfilter tools.

Then I found svndumpsanitize. Instead of simply parsing revisions in the dump file, it really tries to connect all the revisions where included files are being mentioned, or to sanely and safely skip revisions with excluded files. It might or might not be the tool you need (or needed) but it's worth a shot.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionleftendView Question on Stackoverflow
Solution 1 - SvnSamuelView Answer on Stackoverflow
Solution 2 - SvncompieView Answer on Stackoverflow
Solution 3 - SvnAdam BellaireView Answer on Stackoverflow
Solution 4 - SvnPeter StoneView Answer on Stackoverflow
Solution 5 - SvnniosView Answer on Stackoverflow
Solution 6 - SvnRenatoView Answer on Stackoverflow
Solution 7 - SvnRade_303View Answer on Stackoverflow