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

7

158

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?

Luby answered 6/1, 2009 at 19:5 Comment(0)
L
184

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.

Leyte answered 6/1, 2009 at 19:14 Comment(11)
Nice example. Note that as stated in the documentation I linked to, this solution will re-number all of the revisions so that there are no "empties". Something to keep in mind if you reference the doc revisions anywhere else.Kalil
I suggested the removal of empty revisions to avoid adding a bunch of empty revisions to the target repository, most likely confusing anyone that didn't know about the load. Since --preserve-revprops will keep the commit messages instead of the using the default one of loading.Leyte
Thanks for the answer. In case anyone needs to know, if you need more then one folder just put a space between them in the include list. Ex. ... include folderOne folderTwoPony
Renumbering revisions is probably a bad idea, as commit messages and issue tracking tools may refer to themLianne
Thanks! +1! However I had a problem because I changed the name of the /path/to/docs during its history, and the svn filtering job failed. To solve the issue, I had to add all the previous paths to the svndumpfilter command: "svndumpfilter include path/to/docs1 path/to/docs2 --drop-empty- ....". Cheers!Nettie
This worked for me. I'm a windows user (Visual SVN Server) and my first command looked like this, if it helps anyone: "C:\Program Files (x86)\VisualSVN Server\bin\svnadmin" dump c:\Repositories\MyRepository > c:\Temp\MyReository.dumpTired
I have a repo called stuff with folders called thing1 and thing2. I used svndumpfilter to pull just thing1. History still shows all commits to things folder. why?Triad
See also this answer with tips for dumping only the right revision https://mcmap.net/q/152638/-svn-move-code-with-history-between-two-repositoriesDelorisdelorme
If you want to move to a particular directory in the destination repository, use --parent-dir destinationfolder parameter in svnadmin load?Underfur
how to do this when both repository are at remote location. svnadmin is not recognizing URL. i tried to use svnrdump command but not sure what i am doing wrong.Muliebrity
For anyone else who's wondering: the path/to/docs part of the second command should be relative to the repository root. For example "trunk\job" (backslash because I'm on Windows)Booboo
M
30

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.

Massenet answered 2/4, 2009 at 9:0 Comment(2)
Here's a better link for svndumpfilter2: svn.tartarus.org/sgt/svn-tools/svndumpfilter2Toddler
You can in that case add the required path to the list ... being as specific as possible ... and then remove those entries from the project after import.Tack
K
6

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.

Kalil answered 6/1, 2009 at 19:10 Comment(0)
Q
2

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 Samuel describes.

Quentinquercetin answered 6/1, 2009 at 19:9 Comment(1)
However, you cannot keep the revisions without access to the repository itself. If you can only have a working copy, this is the best he can do.Leyte
G
2

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.

Geber answered 5/10, 2011 at 9:18 Comment(0)
C
2

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.

Carolinian answered 12/11, 2015 at 13:16 Comment(0)
E
0

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.

Enlace answered 4/11, 2020 at 1:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.