Question

I have some old dump of a SVN repo with a straightforward structure:

trunk/src/
  folder1/
  folder2/
  folder3/
  ...

I know that each folder is in fact a separate project, so I would like to clone this svn repo into git but splitting each folder into separate git repository and preserving history. How can I do that?

I don't need magic loop-scripts. I can name each folder manually. I would only like to know how to clone specific folder from svn into new git repository preserving history.

[Update]

I have only a dump of SVN repo, no SVN server. So I cant do

git svn clone svn://path/to/my/trunk/src/folder1

Instead I'm using

git svn clone file://path/to/my/dump

[What I tried]

I've used svnadmin to create a svn dump file, then used svndumpfilter to filter out only folders that I need. I managed to split the original svn dump into separate files, one for each folder.

svnadmin dump /svn/old_repos > ./repository.dump
svndumpfilter include /trunk/scr/folder1
      --drop-empty-revs
      --renumber-revs
      --preserve-revprops
    < ./repository.dump > ./folder1.dump

I tried to use git svn clone file:///path/to/my/folder1.dump but I got this error:

Couldn't open a repository:
    Unable to open an ra_local session to URL:
        Unable to open repository `file://path/to/my/filtered/dump/folder1.dump`
           at /usr/lib/git-core/git-svn line 2143

This looks like the dump file is corrupted. I tried svndump load /repos/folder1 < /path/to/my/folder1.dump but I got another error, this time from svnadmin:

svnadmin: File not found: transaction `0-0`, path `trunk/src/folder1

Any ideas?

Was it helpful?

Solution

This is what did the trick for me:

  1. Create a svn repository dump file for later processing:

    svnadmin dump /svn/old_repo > /tmp/svn/repository.dump

  2. Use svndumpfilter to split dump file into separate dumps:

    svndumpfilter include /trunk/scr/folder1 --drop-empty-revs --renumber-revs --preserve-revprops < /tmp/svn/repository.dump > /tmp/svn/dump/folder1.dump

  3. Create new empty svn repository

    svnadmin create /tmp/svn/repos/folder1

  4. Create root dir insde new empty svn repository. This is very important! I missed that step and almost gone mad due to some unclear svnadmin erros:

    svn mkdir file:///tmp/svn/repos/folder1/trunk/src/folder1 --parents -m "Go"

  5. Load new dump into empty svn repository:

    svnadmin load /tmp/svn/repos/folder1 < /tmp/svn/dump/folder1.dump

  6. Now some git magic. Note the -T arg - it's very handy. I used this to make my life easier and make folder1 a root for git repo. If I didn't do that, I'd end up with a git repo structure like this: trunk/src/folder1/* (that is what I had initially in my svn repo). And I wanted to just have the folder1 as a root:

    git svn clone -T /trunk/src/folder1 file:///tmp/svn/repos/folder1 /new/path/folder1

And that was it. Steps 2-7 repeat for each directory for which you want to have a new git repository. I ended up writing a simple script for that.

OTHER TIPS

Something like

git svn clone svn://path/to/your/trunk/src/folder1 

?

Subversion directories are usually considered as a sort of repositories on themselves.

Note that there will be no SVN branch and tag integration in this case.

In case of a dump you probably need to import it somewhere (into a temporarly local SVN repository, for example).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top