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

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

    reposurgeon

    For complicated cases, reposurgeon by Eric S. Raymond is the tool of choice. In addition to SVN, it supports many other version control systems via the fast-export format, and also CVS. The author reports successful conversions of ancient repositories such as Emacs and FreeBSD.

    The tool apparently aims at near perfect conversion (such as converting SVN's svn:ignore properties to .gitignore files) even for difficult repository layouts with a long history. For many cases, other tools might be easier to use.

    Before delving into the documentation of the reposurgeon command line, be sure to read the excellent DVCS migration guide which goes over the conversion process step by step.

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

    Download the Ruby installer for Windows and install the latest version with it. Add Ruby executables to your path.

    • Install svn2git
    • Start menu -> All programs -> Ruby -> Start a command prompt with Ruby
    • Then type “gem install svn2git” and enter

      Migrate Subversion repository

    • Open a Ruby command prompt and go to the directory where the files are to be migrated

      Then svn2git http://[domain name]/svn/ [repository root]

    • It may take few hours to migrate the project to Git depends on the project code size.

    • This major step helps in creating the Git repository structure as mentioned below.

      SVN (/Project_components) trunk --> Git master SVN (/Project_components) branches --> Git branches SVN (/Project_components) tags --> Git tags

    Create the remote repository and push the changes.

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

    Cleanly Migrate Your Subversion Repository To a Git Repository. First you have to create a file that maps your Subversion commit author names to Git commiters, say ~/authors.txt:

    jmaddox = Jon Maddox <jon@gmail.com>
    bigpappa = Brian Biggs <bigpappa@gmail.com>
    

    Then you can download the Subversion data into a Git repository:

    mkdir repo && cd repo
    git svn init http://subversion/repo --no-metadata
    git config svn.authorsfile ~/authors.txt
    git svn fetch
    

    If you’re on a Mac, you can get git-svn from MacPorts by installing git-core +svn.

    If your subversion repository is on the same machine as your desired git repository, then you can use this syntax for the init step, otherwise all the same:

    git svn init file:///home/user/repoName --no-metadata
    
    0 讨论(0)
  • 2020-11-22 03:54

    Here is a simple shell script with no dependencies that will convert one or more SVN repositories to git and push them to GitHub.

    https://gist.github.com/NathanSweet/7327535

    In about 30 lines of script it: clones using git SVN, creates a .gitignore file from SVN::ignore properties, pushes into a bare git repository, renames SVN trunk to master, converts SVN tags to git tags, and pushes it to GitHub while preserving the tags.

    I went thru a lot of pain to move a dozen SVN repositories from Google Code to GitHub. It didn't help that I used Windows. Ruby was all kinds of broken on my old Debian box and getting it working on Windows was a joke. Other solutions failed to work with Cygwin paths. Even once I got something working, I couldn't figure out how to get the tags to show up on GitHub (the secret is --follow-tags).

    In the end I cobbled together two short and simple scripts, linked above, and it works great. The solution does not need to be any more complicated than that!

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

    We can use git svn clone commands as below.

    • svn log -q <SVN_URL> | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt

    Above command will create authors file from SVN commits.

    • svn log --stop-on-copy <SVN_URL>

    Above command will give you first revision number when your SVN project got created.

    • git svn clone -r<SVN_REV_NO>:HEAD --no-minimize-url --stdlayout --no-metadata --authors-file authors.txt <SVN_URL>

    Above command will create the Git repository in local.

    Problem is that it won't convert branches and tags to push. You will have to do them manually. For example below for branches:

    $ git remote add origin https://github.com/pankaj0323/JDProjects.git
    $ git branch -a
    * master
      remotes/origin/MyDevBranch
      remotes/origin/tags/MyDevBranch-1.0
      remotes/origin/trunk
    $$ git checkout -b MyDevBranch origin/MyDevBranch
    Branch MyDevBranch set up to track remote branch MyDevBranch from origin.
    Switched to a new branch 'MyDevBranch'
    $ git branch -a
    * MyDevBranch
      master
      remotes/origin/MyDevBranch
      remotes/origin/tags/MyDevBranch-1.0
      remotes/origin/trunk
    $
    

    For tags:

    $git checkout origin/tags/MyDevBranch-1.0
    Note: checking out 'origin/tags/MyDevBranch-1.0'.
    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by performing another checkout.
    
    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -b with the checkout command again. Example:
    
      git checkout -b new_branch_name
    
    HEAD is now at 3041d81... Creating a tag
    $ git branch -a
    * (detached from origin/tags/MyDevBranch-1.0)
      MyDevBranch
      master
      remotes/origin/MyDevBranch
      remotes/origin/tags/MyDevBranch-1.0
      remotes/origin/trunk
    $ git tag -a MyDevBranch-1.0 -m "creating tag"
    $git tag
    MyDevBranch-1.0
    $
    

    Now push master, branches and tags to remote git repository.

    $ git push origin master MyDevBranch MyDevBranch-1.0
    Counting objects: 14, done.
    Delta compression using up to 8 threads.
    Compressing objects: 100% (11/11), done.
    Writing objects: 100% (14/14), 2.28 KiB | 0 bytes/s, done.
    Total 14 (delta 3), reused 0 (delta 0)
    To https://github.com/pankaj0323/JDProjects.git
     * [new branch]      master -> master
     * [new branch]      MyDevBranch -> MyDevBranch
     * [new tag]         MyDevBranch-1.0 -> MyDevBranch-1.0
    $
    

    svn2git utility

    svn2git utility removes manual efforts with branches and tags.

    Install it using command sudo gem install svn2git. After that run below command.

    • $ svn2git <SVN_URL> --authors authors.txt --revision <SVN_REV_NO>

    Now you can list the branches, tags and push them easily.

    $ git remote add origin https://github.com/pankaj0323/JDProjects.git
    $ git branch -a
      MyDevBranch
    * master
      remotes/svn/MyDevBranch
      remotes/svn/trunk
    $ git tag
      MyDevBranch-1.0
    $ git push origin master MyDevBranch MyDevBranch-1.0
    

    Imagine you have 20 branches and tags, obviously svn2git will save you a lot of time and that's why I like it better than native commands. It's a nice wrapper around native git svn clone command.

    For a complete example, refer my blog entry.

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

    Magic:

    $ git svn clone http://svn/repo/here/trunk
    

    Git and SVN operate very differently. You need to learn Git, and if you want to track changes from SVN upstream, you need to learn git-svn. The git-svn main page has a good examples section:

    $ git svn --help
    
    0 讨论(0)
提交回复
热议问题