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

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

    I suggest getting comfortable with Git before trying to use git-svn constantly, i.e. keeping SVN as the centralized repo and using Git locally.

    However, for a simple migration with all the history, here are the few simple steps:

    Initialize the local repo:

    mkdir project
    cd project
    git svn init http://svn.url
    

    Mark how far back you want to start importing revisions:

    git svn fetch -r42
    

    (or just "git svn fetch" for all revs)

    Actually fetch everything since then:

    git svn rebase
    

    You can check the result of the import with Gitk. I'm not sure if this works on Windows, it works on OSX and Linux:

    gitk
    

    When you've got your SVN repo cloned locally, you may want to push it to a centralized Git repo for easier collaboration.

    First create your empty remote repo (maybe on GitHub?):

    git remote add origin git@github.com:user/project-name.git
    

    Then, optionally sync your main branch so the pull operation will automatically merge the remote master with your local master, when both contain new stuff:

    git config branch.master.remote origin
    git config branch.master.merge refs/heads/master
    

    After that, you may be interested in trying out my very own git_remote_branch tool, which helps dealing with remote branches:

    First explanatory post: "Git remote branches"

    Follow-up for the most recent version: "Time to git collaborating with git_remote_branch"

提交回复
热议问题