Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert SVN Subdirectory to Git

Tags:

git

svn

git-svn

I would like to ditch SVN for Git. My current SVN repository setup has projects under trunk (/trunk/projecta, /trunk/projectb, etc. with tags and branches at /tags/projecta-1.0, etc.). I would like to create distinct Git repos for each of these projects by pulling them out of SVN using git-svn.

I've successfully pulled the entire SVN repo down to a local Git repo but all of the projects exist in the same Git repo now. Is it possible to pull them apart at this point?

like image 740
magneticMonster Avatar asked May 02 '10 01:05

magneticMonster


3 Answers

This is tricky. To get, e.g., the tags for a project, all its tags have to be under a common directory, but your structure has all projects sharing a single tag directory.

Perhaps you could move /tags/projecta-1.0 to /tags/projecta/1.0 and so on, and then import projects into git one at a time:

git-svn init --trunk=trunk/projecta --tags=tags/projecta ...

I don't know if this will work as expected, so please do this on a copy of your repository, not the original!

like image 149
Marcelo Cantos Avatar answered Nov 15 '22 06:11

Marcelo Cantos


I recently had to solve this problem with a reasonably complex case (extracting the utahrle files from BRL-CAD's overall history to make a separate GIT project) and ended up using svn2git with a rules file. These were my steps - not sure if it's the "right" way but it seems to have succeeded in my case:

  1. Make sure svn2git is installed, as well as subversion and git (enable git subversion support if not already present.) Note that there seem to be multiple programs using the project name svn2git - the one I used is this one:

    http://www.gitorious.org/svn2git

    This article from KDE got me started:

    http://techbase.kde.org/Projects/MoveToGit/UsingSvn2Git

  2. Obtain local copy of your svn repository. Note that this is not a checkout of the repository but a full copy of the entire SVN repo data set. Sourceforge makes this possible with an rsync option - see their docs for details: http://sourceforge.net/p/forge/documentation/rsync%20Backups/. I'm not sure about other sites.

    mkdir svn_repo
    cd svn_repo
    rsync -av svn.code.sf.net::p/PROJECTNAME/MOUNTPOINT .
    cd ..
    
  3. create identity map between svn committers and git committers

    file: account-map

    svnname1 Jane Coder <[email protected]>
    svnname2 Joe Techwriter <[email protected]>
    
  4. create svn2git filtering rules to capture the utahrle history. I'll post the full utahrle example here that shows how to follow the history around between different directories, but I'd expect most cases wouldn't be quite this bad:

    file: rules

    create repository utahrle
    end repository
    
    match /brlcad/trunk/libutahrle/
       min revision 1
       max revision 22796
       repository utahrle
       branch master
    end match
    
    match /brlcad/trunk/tools/
       min revision 1
       max revision 22814
       repository utahrle
       branch master
    end match
    
    match /brlcad/trunk/src/other/libutahrle/
       min revision 22797
       repository utahrle
       branch master
    end match
    
    match /brlcad/trunk/src/other/URToolkit/
       min revision 22815
       repository utahrle
       branch master
    end match
    
    match /
    end match
    
  5. Run svn-all-fast-export to generate archive (svn_repo is the directory holding your full copy of the subversion files):

    svn-all-fast-export --identity-map account-map --rules rules svn_repo

  6. Using the above rules file, utahrle holds the resultant git repository. Use gitk to check that the history we expect to see is actually present, then (if you are using this repo as an online source archive) use standard sourceforge procedures for uploading an existing git repository.

like image 41
starseeker Avatar answered Nov 15 '22 06:11

starseeker


Another program for one-time conversion of Subversion repository is Svn2Git (different than vdboor's answer), it has fewer dependencies and did great job for my repositories.

like image 40
CharlesB Avatar answered Nov 15 '22 05:11

CharlesB