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

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

    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!

提交回复
热议问题