如何将svn分支和标签导入git-svn? [英] How to import svn branches and tags into git-svn?

查看:311
本文介绍了如何将svn分支和标签导入git-svn?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我必须承诺的中央SVN仓库,但我对git充满热情(就像我认识的任何其他开发人员一样)。这个案例是众所周知的。

然后我读了关于git-svn并试了一下。因为我不需要完整的历史记录,仅仅两个月左右,我确实喜欢这样:
$ b $ p $ git svn clone -r 34000 - s的https://svn.ourdomain.com/svn/repos/Project/SubProject



子项目像往常一样拥有子目录 trunk 标记分支。然后,为了获得最后一次修订,我做了

git svn rebase



稍后的一些下载很棒。上次修订版本,日志等。好吧,现在我将切换到我的功能分支。



$ git branch

* master $ p $ git branch -r

trunk



$ git branch -a

* master

remotes / trunk



问题是:我的分支在哪里?我做错了什么?我应该怎么做才能让我的分支机构进入新的git回购?

git-svn,无论我读了什么,都明智地处理了分支和标签,但行为并不符合我的预期。谢谢!



编辑:我刚刚发现会执行它。但它会得到所有修订,这是我不喜欢的。

b
$ b


  1. 提供适当的主干,分支和标签文件夹名称和提取svn回购:

      git svn init -t tags -b branches -T trunk https://mysvn.com/svnrepo 
    git svn fetch

  2. 由于svn中的标签是真正的分支,因此可以从标签分支中创建git标签:

      git for-each-ref --format =%(refname:short)%(objectname)refs / remotes / tags | cut -d / -f 3- | 
    while read ref
    do
    echo git tag -a $ ref -m'从svn导入标记'
    完成
    $ b $ $ pre $ g $ git for-each- ref --format =%(refname:short)refs / remotes / tags | cut -d / -f 2- |
    while read read
    do
    echo git branch -rd $ ref
    done


  3. 由于上一步中标记的标签指向提交创建标签,我们需要派生真实标签,即创建标签提交的父项。
    $ b

      git for-each-ref --format =%(refname:short)refs / tags | 
    同时读取ref
    do
    tag =`echo $ ref | sed的/_/./ g'`#赋予标签一个新名称
    echo $ ref -\> $ tag
    git tag -a $ tag`git rev-list -2 $ ref |尾巴-1' -m正确的svn标签
    完成


  4. 现在必须去掉旧的标签。



I have got a central SVN repository I must commit to, but I've got a passion for git (like any other developer I know). The case is well known.

Then I read about git-svn and gave it a try. Since I don't need the full history, just from two months or so, I did like this:

git svn clone -r 34000 -s https://svn.ourdomain.com/svn/repos/Project/SubProject

SubProject had, as usual, the subdirectories trunk, tags and branches. Great.

Then, in order to get the last revision, I did

git svn rebase

Some downloads later, great. Last revision, logs, etc. Ok, now I'll switch to my feature branch.

$ git branch
* master

$ git branch -r
trunk

$ git branch -a
* master
remotes/trunk

The questions are: Where are my branches? Have I done something wrong? How should I do in order to get my branches in the new git repo?

git-svn, wherever I have read about it, dealt wisely with branches and tags, but the behaviour is not what I expected. Thanks!

EDIT: I have just found out that git svn fetch will do it. But it will get all revisions, which is something I wouldn't like.

解决方案

You'll need several steps.

  1. supply proper trunk, branches and tags folder names and fetch svn repo:

    git svn init -t tags -b branches -T trunk https://mysvn.com/svnrepo
    git svn fetch
    

  2. Since tags in svn are real branches, create git tags from tag branches:

    git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/tags |  cut -d / -f 3- |
    while read ref
    do
      echo git tag -a $ref -m 'import tag from svn'
    done
    

  3. Delete tag branches

    git for-each-ref --format="%(refname:short)" refs/remotes/tags | cut -d / -f 2- |
    while read ref
    do 
      echo git branch -rd $ref
    done
    

  4. Since tags marked in the previous step point to a commit "create tag", we need to derive "real" tags, i.e. parents of "create tag" commits.

    git for-each-ref --format="%(refname:short)" refs/tags |
    while read ref
    do
      tag=`echo $ref | sed 's/_/./g'` # give tags a new name
      echo $ref -\> $tag
      git tag -a $tag `git rev-list -2 $ref | tail -1` -m "proper svn tag"
    done
    

  5. All we have to do now is to remove old tags.

这篇关于如何将svn分支和标签导入git-svn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆