search

Home  >  Q&A  >  body text

Migrating svn to git, branches are gone?

According to the documentation on progit: http://git-scm.com/book/zh/v2/Git-与其他系统-迁移到-Git

Encountered two problems:

To change the tag to a proper Git tag, run

 $ cp -Rf .git/refs/remotes/origin/tags/* .git/refs/tags/
 $ rm -Rf .git/refs/remotes/origin/tags

This will turn the remote branch references originally in remotes/origin/tags/ into real (lightweight) tags.
Next, move the remaining references under refs/remotes to local branches:

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

.git/refs/remotes Now all old branches are real Git branches, and all old tags are real Git tags.
The last thing to do is to add your new Git server as a remote repository and push to it.

But when executing cp, it was found that this directory does not exist. git branch -r lists many original ones

$git branch -r
origin/v1.1
origin/tags/v1.1.2
origin/tags/v1.1.2@438
origin/tags/v1.2.1
origin/tags/v1.2.1@474
origin/tags/v1.2.3
origin/trunk

However, there is no file under .git/refs/remotes/origin/tags
Referencehttp://nowing.iteye.com/blog/844608的做法,使用标准命令将branch转成tags

$ git tag tagname tags/tagname     ----用指定的分支创建一个Git标签 
$ git branch -r -d tags/tagname    ----删除指定的远程分支

Finally, use git push origin --all to push to the git server, but there is only the trunk and no branches.
Use git push origin master --tags to have the trunk and tags, but there are no branches

The final question comes, how to migrate the branch?

巴扎黑巴扎黑2793 days ago608

reply all(2)I'll reply

  • 世界只因有你

    世界只因有你2017-05-02 09:25:00

    After struggling for a long time, I finally solved it with svn2git
    The basic idea is to convert the remote branch to the local branch, and then push
    svn2git can do it directly

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-02 09:25:00

     git svn clone http://myhost/repo -T trunk -b branches -t tags 
     #将svn仓库转为git仓库
     git remote add oscgit https://git.oschina.net/user/repo #添加remote,这个需要在页面上建立
     git push -u origin --all
    

    reply
    0
  • Cancelreply