Converting svn to git, how to get the branches not to be just remote in the svn repo?

前端 未结 4 1613
太阳男子
太阳男子 2021-02-04 04:28

I\'m quite new to git and I\'m trying to move a svn repository to git. I followed the guide below so now I have a git repo on my server
http://pauldowman.com/2008/07/26/how-

相关标签:
4条回答
  • 2021-02-04 04:58

    I have migrated 2 svn repos to git (git version 1.7.0.4) following Scott's recipe, a smaller one and a larger one. The smaller one behaved as described by Scott in the book chapter. The larger one required David's solution. Another thing is that

    $ git push origin --all
    

    did not push any tags and instead I had to do this:

    $ git push origin --all
    $ git push origin --tags
    

    This may not be obvious from the flag --all and from the book chapter and I realized this after I have deleted the local git svn repo.

    0 讨论(0)
  • 2021-02-04 05:00

    There is a fairly detailed explanation on how to do a pretty good SVN import that explains how to convert the branches properly here:

    https://git-scm.com/book/en/v1/Git-and-Other-Systems-Migrating-to-Git

    The short answer is to run this:

    $ cp -Rf .git/refs/remotes/* .git/refs/heads/
    $ rm -Rf .git/refs/remotes
    

    Hope that's helpful.

    0 讨论(0)
  • Scott's solution didn't work for me. I suspect something may have changed in a recent version of git-svn since he posted that (and since the linked book was written), as it seems to aggressively garbage-collect as soon as the clone is complete. But this is just a guess as to why it didn't work. I'm using git 1.6.5.6.

    Specifically, my .git/refs/remotes directory was completely empty except for a tags directory, which was also empty. So there is nothing I can copy to make it right.

    After some poking around, I was able to fix this by checking the file .git/packed-refs and doing search-and-replace on the following (in this order):

    refs/remotes/tags => refs/tags
    refs/remotes => refs/heads
    

    If your editor is vim, you can do it with these two commands:

    :%s/refs\/remotes\/tags/refs\/tags/g
    :%s/refs\/remotes/refs\/heads/g
    

    svn2git 1.3.1 also did not produce a usable result for me (did not import any commits after a certain point several months ago, and branches all showed the same commits). For now I have given up on svn2git and have had the most success using git-svn combined with the above.

    Wishful thinking: sure would be nice if git-svn simply added a command like 'abandon' or 'migrate' that would automate this process in a future-proof way.

    0 讨论(0)
  • 2021-02-04 05:09

    Another good way to do this, just for the record, is to use svn2git — I'm in the middle of converting several rather large repositories and it has been a godsend. It automates all of the steps needed to take care of branches and convert svn tags to real git tags.

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