How do I migrate an SVN repository with history to a new Git repository?

前端 未结 30 1633
离开以前
离开以前 2020-11-22 02:51

I read the Git manual, FAQ, Git - SVN crash course, etc. and they all explain this and that, but nowhere can you find a simple instruction like:

SVN repository in: <

相关标签:
30条回答
  • 2020-11-22 03:36

    I just wanted to add my contribution to the Git community. I wrote a simple bash script which automates the full import. Unlike other migration tools, this tool relies on native git instead of jGit. This tool also supports repositories with a large revision history and or large blobs. It's available via github:

    https://github.com/onepremise/SGMS

    This script will convert projects stored in SVN with the following format:

    /trunk
      /Project1
      /Project2
    /branches
         /Project1
         /Project2
    /tags
     /Project1
     /Project2
    

    This scheme is also popular and supported as well:

    /Project1
         /trunk
         /branches
         /tags
    /Project2
         /trunk
         /branches
         /tags
    

    Each project will get synchronized over by project name:

    Ex: ./migration https://svnurl.com/basepath project1
    

    If you wish to convert the full repo over, use the following syntax:

    Ex: ./migration https://svnurl.com/basepath .
    
    0 讨论(0)
  • 2020-11-22 03:36

    There are different methods to achieve this goal. I've tried some of them and found really working one with just git and svn installed on Windows OS.

    Prerequisites:

    1. git on windows (I've used this one) https://git-scm.com/
    2. svn with console tools installed (I've used tortoise svn)
    3. Dump file of your SVN repository. svnadmin dump /path/to/repository > repo_name.svn_dump

    Steps to achieve final goal (move all repository with history to a git, firstly local git, then remote)

    1. Create empty repository (using console tools or tortoiseSVN) in directory REPO_NAME_FOLDER cd REPO_NAME_PARENT_FOLDER, put dumpfile.dump into REPO_NAME_PARENT_FOLDER

    2. svnadmin load REPO_NAME_FOLDER < dumpfile.dump Wait for this operation, it may be long

    3. This command is silent, so open second cmd window : svnserve -d -R --root REPO_NAME_FOLDER Why not just use file:///...... ? Cause next command will fail with Unable to open ... to URL:, thanks to the answer https://stackoverflow.com/a/6300968/4953065

    4. Create new folder SOURCE_GIT_FOLDER

    5. cd SOURCE_GIT_FOLDER
    6. git svn clone svn://localhost/ Wait for this operation.

    Finally, what do we got?

    Lets check our Local repository :

    git log
    

    See your previous commits? If yes - okay

    So now you have fully functional local git repository with your sources and old svn history. Now, if you want to move it to some server, use the following commands :

    git remote add origin https://fullurlpathtoyourrepo/reponame.git
    git push -u origin --all # pushes up the repo and its refs for the first time
    git push -u origin --tags # pushes up any tags
    

    In my case, I've dont need tags command cause my repo dont have tags.

    Good luck!

    0 讨论(0)
  • 2020-11-22 03:37

    See the official git-svn manpage. In particular, look under "Basic Examples":

    Tracking and contributing to an entire Subversion-managed project (complete with a trunk, tags and branches):

    # Clone a repo (like git clone):
        git svn clone http://svn.foo.org/project -T trunk -b branches -t tags
    
    0 讨论(0)
  • 2020-11-22 03:37

    Several answers here refer to https://github.com/nirvdrum/svn2git, but for large repositories this can be slow. I had a try using https://github.com/svn-all-fast-export/svn2git instead which is a tool with exactly the same name but was used to migrate KDE from SVN to Git.

    Slightly more work to set it up but when done the conversion itself for me took minutes where the other script spent hours.

    0 讨论(0)
  • 2020-11-22 03:37

    Converting svn submodule/folder 'MyModule' into git with history without tags nor branches.

    • git svn clone --no-metadata --trunk=SomeFolder1/SomeFolder2/SomeFolder3/MyModule http://svnhost:port/repo_root_folder/MyModule_temp -A C:\cheetah\svn\authors-transform.txt
    • git clone MyModule_temp MyModule
    • cd MyModule
    • git flow init
    • git remote set-url origin https://userid@stashhost/stash/scm/xyzxyz/MyModule.git
    • git push -u origin master
    • git push -u origin develop

    To retain svn ignore list use the above comments after step 1

    0 讨论(0)
  • 2020-11-22 03:38

    This guide on atlassian's website is one of the best I have found:

    https://www.atlassian.com/git/migration

    This tool - https://bitbucket.org/atlassian/svn-migration-scripts - is also really useful for generating your authors.txt among other things.

    0 讨论(0)
提交回复
热议问题