Convert SVN Subdirectory to Git

前端 未结 4 844
陌清茗
陌清茗 2020-12-24 02:14

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 b

4条回答
  •  被撕碎了的回忆
    2020-12-24 02:56

    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 
      svnname2 Joe Techwriter 
      
    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.

提交回复
热议问题