在SVN迁移到Git期间,将SVN远程分支和标记转换为本地Git分支/标记的正确方法是什么? [英] What is the correct way to convert SVN remote branches and tags into local Git branches/tags during SVN to Git migration

查看:87
本文介绍了在SVN迁移到Git期间,将SVN远程分支和标记转换为本地Git分支/标记的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将git-svn init / git-svn提取到本地Git分支/标记之前,使远程分支/标记存在的正确方法是什么?推送到远程Git仓库并完全放弃SVN。



我有:


  • 运行 git svn init
  • 将我的.git / config文件的 svn-remotesvn部分更新为以下内容:

      url = file:/// Users / Developers / git_transition / svn_repo 
    fetch = cascade / trunk:refs / remotes / svn / trunk
    branches = cascade / branches / {5.0GA_CLEANUP,drag-n-drop-def-builder,help-text,hib-annotations,hibernate-annotations,图像编辑器,ldapconfig,liquibase,move -rename-prototype,progress-bar,progress-bar2,quartz-upgrade,recyclebin,rendering_metrics,shuttle_upgrade,spring3,web-services-no-nuller}:refs / remotes / svn / *
    ranches = cascade / branches /{6.x,5.x,4.x,3.x,archive}/*:refs/remotes/svn/*
    tags = cascade / tags / {3.7.x,4.x,5 .X,6.x中,旧版本} / *:参/遥控器/ SVN /标记/ *


  • 运行 git svn fetch

    $ g $ s $ g $ g $ s $ g $ g $ g $ g $ c $ g $ init / fetch将这些分支/标签变成本地分支?



    我试过关于Pro Git的建议,但除了空的6.x,5.x,4.x,3.x之外,.git / refs / remotes / svn /目录中没有任何内容。 ,标签和归档目录。我确实验证了远程分支在那里 git branch -r



    有人建议我需要系统地将所有的远程分支签出为本地分支: git checkout -b< local_branch_name> < svn_remote_branch_name> 但我在任何地方都没有得到确切的答案。 通过使用这个脚本:

      git for-each-ref --format =%(refname)refs / remotes /svn/tags/6.x | 
    grep -v @ |同时读取标签; GIT_COMMITTER_DATE =$(git log -1
    --pretty = format:%ad$ tag)GIT_COMMITTER_EMAIL =$(git log -1
    --pretty = format: (git log -1
    --pretty = format:%cn$ tag)git tag -m$(git log -1
    --pretty = format:%s%n%b$ tag)$ {tag#refs / remotes / svn / tags / 6.x /}
    $ tag;为每个标签文件夹完成

    对于像这样的一次性操作,在离开SVN回购之前,我喜欢使用ruby脚本克隆它 svn2git
    $ b


    ===示例



    假设我在svn中有这样的代码:



     主干
    ...
    分支
    1.x
    2.x
    标签
    1.0.0
    1.0.1
    1.0.2
    1.1.0
    2.0.0




    git-svn 将通过提交历史记录来构建新的git仓库。

    它会将所有分支和标签导入为远程svn分支,而你真正想要的是git-native本地分支和git标签对象。

    所以在导入这个项目之后,我会通用电器t:



      $ git分支
    * master
    $ git分支-a
    * master
    1.x
    2.x
    tags / 1.0.0
    tags / 1.0.1
    tags / 1.0.2
    tags / 1.1.0
    tags / 2.0.0
    trunk
    $ git tag -l
    [空]




    在您的项目完成 svn2git 后,您会看到而不是:



      $ git branch 
    * master
    1.x
    2.x
    $ git tag -l
    1.0.0
    1.0.1
    1.0.2
    1.1.0
    2.0。 0


    What is the correct way to make the remote branches/tags that exist after a git-svn init/git-svn fetch into local Git branches/tags before pushing to my remote Git repo and abandoning SVN altogether.

    I have:

    • Run git svn init
    • Updated the svn-remote "svn" section of my .git/config file to the following:

      url = file:///Users/Developers/git_transition/svn_repo
      fetch = cascade/trunk:refs/remotes/svn/trunk
      branches = cascade/branches/{5.0GA_CLEANUP,drag-n-drop-def-builder,help-text,hib-annotations,hibernate-annotations,image-editor,ldapconfig,liquibase,move-rename-prototype,progress-bar,progress-bar2,quartz-upgrade,recyclebin,rendering_metrics,shuttle_upgrade,spring3,web-services-no-nuller}:refs/remotes/svn/*
      branches = cascade/branches/{6.x,5.x,4.x,3.x,archive}/*:refs/remotes/svn/*
      tags = cascade/tags/{3.7.x,4.x,5.x,6.x,old-releases}/*:refs/remotes/svn/tags/*
      

    • Run git svn fetch

    Does git-svn clone do something beyond init/fetch that turns these branches/tags into local ones?

    I tried the advice on Pro Git but there was nothing in the .git/refs/remotes/svn/ directory except the empty 6.x, 5.x, 4.x, 3.x, tags, and archive directories. I did verify that the remote branches are there with git branch -r.

    Someone suggested that I needed to systematically checkout all of the remote branches as local ones: git checkout -b <local_branch_name> <svn_remote_branch_name> but I haven't gotten a definitive answer anywhere.

    I have been able to conver the tags by using this script:

    git for-each-ref --format="%(refname)" refs/remotes/svn/tags/6.x |
    grep -v @ | while read tag; do GIT_COMMITTER_DATE="$(git log -1
    --pretty=format:"%ad" "$tag")" GIT_COMMITTER_EMAIL="$(git log -1
    --pretty=format:"%ce" "$tag")" GIT_COMMITTER_NAME="$(git log -1
    --pretty=format:"%cn" "$tag")" git tag -m "$(git log -1
    --pretty=format:"%s%n%b" "$tag")" ${tag#refs/remotes/svn/tags/6.x/}
    "$tag"; done
    

    for each of the tags folders.

    解决方案

    For a one-shot operation like this, before leaving behind a SVN repo, I like to clone it using the ruby script svn2git

    === Examples

    Say I have this code in svn:

      trunk
        ...
      branches
        1.x
        2.x
      tags
        1.0.0
        1.0.1
        1.0.2
        1.1.0
        2.0.0
    

    git-svn will go through the commit history to build a new git repo.
    It will import all branches and tags as remote svn branches, whereas what you really want is git-native local branches and git tag objects.
    So after importing this project I'll get:

      $ git branch
      * master
      $ git branch -a
      * master
        1.x
        2.x
        tags/1.0.0
        tags/1.0.1
        tags/1.0.2
        tags/1.1.0
        tags/2.0.0
        trunk
      $ git tag -l
      [ empty ]
    

    After svn2git is done with your project, you'll get this instead:

      $ git branch
      * master
        1.x
        2.x
      $ git tag -l
        1.0.0
        1.0.1
        1.0.2
        1.1.0
        2.0.0
    

    这篇关于在SVN迁移到Git期间,将SVN远程分支和标记转换为本地Git分支/标记的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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