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

前端 未结 30 1616
离开以前
离开以前 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:41

    If you are using SourceTree you can do this directly from the app. Goto File -> New/Clone then do the following:

    1. Enter the remote SVN URL as the "Source Path / URL".
    2. Enter your credentials when prompted.
    3. Enter the local folder location as the "Destination path".
    4. Give it a name.
    5. In the advanced options select "Git" from the dropdown in "Create local repository of type".
    6. You can optionally specify a revision to clone from.
    7. Hit Clone.

    Open the repo in SourceTree and you'll see your commit messages have been migrated too.

    Now go to Repository -> Repository Settings and add the new remote repo details. Delete the SVN remote if you wish (I did this through the "Edit Config File" option.

    Push the code to the new remote repo when you are ready and code freely.

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

    As another aside, the git-stash command is a godsend when trying to git with git-svn dcommits.

    A typical process:

    1. set up git repo
    2. do some work on different files
    3. decide to check some of the work in, using git
    4. decide to svn-dcommit
    5. get the dreaded "cannot commit with a dirty index" error.

    The solution (requires git 1.5.3+):

    git stash; git svn dcommit ; git stash apply
    
    0 讨论(0)
  • 2020-11-22 03:43

    GitHub now has a feature to import from an SVN repository. I never tried it, though.

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

    I used the svn2git script and works like a charm.

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

    For GitLab users I've put up a gist on how I migrated from SVN here:

    https://gist.github.com/leftclickben/322b7a3042cbe97ed2af

    Steps to migrate from SVN to GitLab

    Setup

    • SVN is hosted at svn.domain.com.au.
    • SVN is accessible via http (other protocols should work).
    • GitLab is hosted at git.domain.com.au and:
      • A group is created with the namespace dev-team.
      • At least one user account is created, added to the group, and has an SSH key for the account being used for the migration (test using ssh git@git.domain.com.au).
      • The project favourite-project is created in the dev-team namespace.
    • The file users.txt contains the relevant user details, one user per line, of the form username = First Last <address@domain.com.au>, where username is the username given in SVN logs. (See first link in References section for details, in particular answer by user Casey).

    Versions

    • subversion version 1.6.17 (r1128011)
    • git version 1.9.1
    • GitLab version 7.2.1 ff1633f
    • Ubuntu server 14.04

    Commands

    bash
    git svn clone --stdlayout --no-metadata -A users.txt 
    http://svn.domain.com.au/svn/repository/favourite-project
    cd favourite-project
    git remote add gitlab git@git.domain.com.au:dev-team/favourite-project.git
    git push --set-upstream gitlab master
    

    That's it! Reload the project page in GitLab web UI and you will see all commits and files now listed.

    Notes

    • If there are unknown users, the git svn clone command will stop, in which case, update users.txt, cd favourite-project and git svn fetch will continue from where it stopped.
    • The standard trunk-tags-branches layout for SVN repository is required.
    • The SVN URL given to the git svn clone command stops at the level immediately above trunk/, tags/ and branches/.
    • The git svn clone command produces a lot of output, including some warnings at the top; I ignored the warnings.
    0 讨论(0)
  • 2020-11-22 03:46

    GitHub has an importer. Once you've created the repository, you can import from an existing repository, via its URL. It will ask for your credentials if applicable and go from there.

    As it's running it will find authors, and you can simply map them to users on GitHub.

    I have used it for a few repositories now, and it's pretty accurate and much faster too! It took 10 minutes for a repository with ~4000 commits, and after it took my friend four days!

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