svn迁移到git

I have worked with SVN for a long time and recently I have started working on Git. After getting familiar with Git, I can clearly say that it’s far better than SVN. If you work with multiple branches and take a merge between branches or reintegrate (svn terminology) then you will know the benefit of Git over SVN.

我已经在SVN上工作了很长时间,最近我开始研究Git。 熟悉Git之后,我可以清楚地说它比SVN好得多。 如果您使用多个分支机构,并在分支机构之间进行合并或重新集成(SVN术语),那么您将了解Git优于SVN的优势。

I have recently moved my Google Code project to Github since google code is closed, so I thought to write a tutorial on SVN to Git Migration.

自从Google代码关闭以来,我最近将我的Google Code项目移到了Github,所以我想写一篇关于SVN到Git Migration的教程。

First we will look into using Git native commands to migrate the SVN repository to Git repository and then see what are the drawbacks and then we will do the same thing with SVN2Git tool.

首先,我们将研究使用Git本机命令将SVN存储库迁移到Git存储库,然后看看有哪些缺点,然后我们将使用SVN2Git工具执行相同的操作

SVN and Git Repositories Details:

SVN和Git存储库详细信息:

  • SVN Repository: I have created a public repository online, it’s URL is https://pl6.projectlocker.com/JournalDev/JDProject/svn . Below image shows the directory structure.

    Notice that I have a standard directory structure with trunk, branches and tags. I have also created an extra file (README.txt) that is outside this directory hierarchy.

    SVN存储库 :我已经在线创建了一个公共存储库,其URL是https://pl6.projectlocker.com/JournalDev/JDProject/svn 。 下图显示了目录结构。

    注意,我有一个带有主干分支标签的标准目录结构。 我还创建了一个额外的文件(README.txt),该文件不在此目录层次结构中。

  • GIT Repository: I am using Github as my repository. It’s free to use and my project git URL is https://github.com/pankaj0323/JDProjects.gitGIT存储库 :我正在使用Github作为我的存储库。 它是免费使用的,我的项目git URL是https://github.com/pankaj0323/JDProjects.git

用于SVN到Git迁移的Git本机命令 (Git Native Commands for SVN to Git Migration)

  1. First step is to create the authors file from the SVN commits, below is the command for that. We need this file for git migration. It’s a big command, make sure you put all these in a single command.

    $ svn log -q https://pl6.projectlocker.com/JournalDev/JDProject/svn | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt

    After this, you will have authors.txt file that will have all the authors details who have committed code into this SVN project.

    之后,您将拥有authors.txt文件,其中将包含已向该SVN项目提交代码的所有作者详细信息。

  2. Find the revision number at which project was created. Use command below:
    $ svn log --stop-on-copy https://pl6.projectlocker.com/JournalDev/JDProject/svn

    You will get the first revision number, if you have a bigger project with release cycles and you are importing from specific release, then this number could be something different. For me it’s 1 because I just created this sample SVN project for this tutorial.

    您将获得第一个修订版本号,如果您有一个较大的项目并具有发行周期,并且要从特定发行版中导入,则此版本号可能有所不同。 对我来说是1,因为我刚刚为本教程创建了这个示例SVN项目。

  3. Run below command to use git svn clone to convert your SVN project into Git. Use revision number when your project repository was created.

    Passing –no-minimize-url will allow git svn to accept URLs as-is without attempting to connect to a higher level directory.

    For other options, read git-svn documentation.

    $ git svn clone -r1:HEAD --no-minimize-url --stdlayout --no-metadata --authors-file authors.txt https://pl6.projectlocker.com/JournalDev/JDProject/svn
    Initialized empty Git repository in /Users/pankaj/temp/SVN_TO_GIT/svn/.git/
    r2 = 06ca74b0800199e459628cec09a559491da39999 (refs/remotes/origin/trunk)A abc.html
    r3 = ba90b46b60785a7fbd583e4ac197e4e8052e61b5 (refs/remotes/origin/trunk)A ClassM2.java
    r4 = 3667ce254366e8e020b6e9516979695d9f00f1b9 (refs/remotes/origin/trunk)
    Found possible branch point: https://pl6.projectlocker.com/JournalDev/JDProject/svn/trunk => https://pl6.projectlocker.com/JournalDev/JDProject/svn/branches/MyDevBranch, 4
    Found branch parent: (refs/remotes/origin/MyDevBranch) 3667ce254366e8e020b6e9516979695d9f00f1b9
    Following parent with do_switch
    Successfully followed parent
    r5 = 6b78ccabce56601ef6de255eab6d7fcd8980f99b (refs/remotes/origin/MyDevBranch)A   branch_file.txt
    r6 = c940c6a4cc2b357985867ca239fba7b91e7038e5 (refs/remotes/origin/MyDevBranch)
    Found possible branch point: https://pl6.projectlocker.com/JournalDev/JDProject/svn/branches/MyDevBranch => https://pl6.projectlocker.com/JournalDev/JDProject/svn/tags/MyDevBranch-1.0, 6
    Found branch parent: (refs/remotes/origin/tags/MyDevBranch-1.0) c940c6a4cc2b357985867ca239fba7b91e7038e5
    Following parent with do_switch
    Successfully followed parent
    r7 = 3041d81b3a4fec5f4ca1b2e04ad5730f67e677b9 (refs/remotes/origin/tags/MyDevBranch-1.0)
    Checked out HEAD:https://pl6.projectlocker.com/JournalDev/JDProject/svn/trunk r4
    $

    运行以下命令以使用git svn clone将SVN项目转换为Git。 创建项目存储库时,请使用修订号。

    传递–no-minimize-url将允许git svn照原样接受URL,而无需尝试连接到更高级别的目录。

    有关其他选项,请阅读git-svn文档 。

  4. You will have the project directory created, go into that and add remote git url as origin.
    $ cd svn
    $ git remote add origin https://github.com/pankaj0323/JDProjects.git

    您将创建项目目录,进入该目录并添加远程git url作为源。

  5. Converting SVN Branches to Git Branches: If you will list branches at this time, you will get something like below.
    $ git branch -a
    * masterremotes/origin/MyDevBranchremotes/origin/tags/MyDevBranch-1.0remotes/origin/trunk
    $

    Git svn clone command makes master from trunk that is ready to be pushed to remote git repository. But we want to push branches too. Use below commands for that:

    将SVN分支转换为Git分支 :如果此时将列出分支,则会得到类似以下的内容。

    $ git branch -a
    * masterremotes/origin/MyDevBranchremotes/origin/tags/MyDevBranch-1.0remotes/origin/trunk
    $

    Git svn clone命令从准备好被推入远程git仓库的主干中创建master。 但是我们也想推动分支机构。 为此,请使用以下命令:

  6. Migrating Tags: Git svn clone command doesn’t create tags, follow below commands for creating tags and make them ready to push to remote.
    $git tag
    $git checkout origin/tags/MyDevBranch-1.0
    Note: checking out 'origin/tags/MyDevBranch-1.0'.You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by performing another checkout.If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -b with the checkout command again. Example:git checkout -b new_branch_nameHEAD is now at 3041d81... Creating a tag
    $ git branch -a
    * (detached from origin/tags/MyDevBranch-1.0)MyDevBranchmasterremotes/origin/MyDevBranchremotes/origin/tags/MyDevBranch-1.0remotes/origin/trunk
    $ git tag -a MyDevBranch-1.0 -m "creating tag"
    $git tag
    MyDevBranch-1.0
    $

    迁移标签 :Git svn clone命令不会创建标签,请遵循以下命令来创建标签,并使它们准备好推送到远程。

  7. Pushing Git Branches and Tags to Remote: My master, branches and tags are ready to be pushed, use below git push command to publish them to remote repository.
    $ git push origin master MyDevBranch MyDevBranch-1.0
    Counting objects: 14, done.
    Delta compression using up to 8 threads.
    Compressing objects: 100% (11/11), done.
    Writing objects: 100% (14/14), 2.28 KiB | 0 bytes/s, done.
    Total 14 (delta 3), reused 0 (delta 0)
    To https://github.com/pankaj0323/JDProjects.git* [new branch]      master -> master* [new branch]      MyDevBranch -> MyDevBranch* [new tag]         MyDevBranch-1.0 -> MyDevBranch-1.0
    $

    将Git分支和标签推送到远程 :我的master,分支和标签已准备好推送,请使用下面的git push命令将它们发布到远程存储库。

That’s it. We have moved our SVN project to Git. While this process seems easy, there are two drawbacks with git svn clone.

而已。 我们已将SVN项目移至Git。 虽然这个过程看起来很简单,但是git svn clone有两个缺点。

  1. It doesn’t create branches for us to push to remote repository. There is a manual work involved, imagine you have 20 branches. It will take a lot of time to create branches and there are chances of errors or typos.它不会为我们创建分支以推送到远程存储库。 涉及手动工作,假设您有20个分支。 创建分支将花费大量时间,并且可能会出现错误或错别字。
  2. No support for tags, I had to checkout the tag as branch and then create tag from it. This is not like moving tags from SVN to Git.不支持标签,我不得不将标签签出为分支,然后从中创建标签。 这不像将标签从SVN移到Git。

使用svn2git工具将SVN迁移到GIT (SVN to GIT Migration using svn2git tool)

svn2git tool solves above two problems with native commands. Before we use this tool, we need to install it. It requires git, git-svn, and ruby installed. svn2git is a ruby wrapper around git’s native SVN support through git-svn. You can install the pre-requisites using below command.

svn2git工具使用本机命令解决了以上两个问题。 在使用此工具之前,我们需要先安装它。 它需要安装git,git-svn和ruby。 svn2git是通过git-svn围绕git的本机SVN支持的Ruby包装。 您可以使用以下命令安装必备组件。

$ sudo apt-get install git-core git-svn ruby
  • Once you have the necessary software on your system, you can install svn2git through rubygems, which will add the svn2git command to your PATH.

    $ sudo gem install svn2git

    Once svn2git is installed, use below commands to migrate SVN repository to Git.

    1. First create the authors file using above command.
    2. Find the initial svn revision from above svn log command.
    3. Use below command to create local git project from svn repository.
    4. Pushing Branches and Tags to Remote Git Repository: You will notice that svn2git has already created Git branches and tags for you to push to remote. Just add the remote origin and push whatever branches and tags you want to remote repository.
      $ git remote add origin https://github.com/pankaj0323/JDProjects.git
      $ git branch -aMyDevBranch
      * masterremotes/svn/MyDevBranchremotes/svn/trunk
      $ git tag
      MyDevBranch-1.0
      $ git push origin master MyDevBranch MyDevBranch-1.0
      Counting objects: 14, done.
      Delta compression using up to 8 threads.
      Compressing objects: 100% (8/8), done.
      Writing objects: 100% (14/14), 2.32 KiB | 0 bytes/s, done.
      Total 14 (delta 3), reused 14 (delta 3)
      To https://github.com/pankaj0323/JDProjects.git* [new branch]      master -> master* [new branch]      MyDevBranch -> MyDevBranch* [new tag]         MyDevBranch-1.0 -> MyDevBranch-1.0
      $

    That’s it. We have migrated SVN repository to Git using svn2git tool. There are various options that we can use with svn2git, for example –notags if you don’t want to migrate tags. Please go through svn2git Usage section for various options. Also note that README.txt file that was not part of standard svn structure is not migrated.

    That’s all for svn to git migration. Based on above analysis, svn2git tool seems a better choice to me than git svn clone native command.

    一旦在系统上安装了必要的软件,就可以通过rubygems安装svn2git,这会将svn2git命令添加到PATH中。

    安装svn2git后,请使用以下命令将SVN信息库迁移到Git。

    1. 首先使用以上命令创建作者文件。
    2. 从上面的svn log命令中找到初始的svn修订版。
    3. 使用以下命令从svn存储库创建本地git项目。
      $ svn2git https://pl6.projectlocker.com/JournalDev/JDProject/svn --authors authors.txt --revision 1
      Initialized empty Git repository in /Users/pankaj/temp/SVN_TO_GIT/.git/
      r2 = 8beacf45e1b82b27bd27891040ea9c77b88d6c37 (refs/remotes/svn/trunk)A    abc.html
      r3 = 52c125d5c68edf2ddd00143d308ba56ea0024f90 (refs/remotes/svn/trunk)A    ClassM2.java
      r4 = f9863ff1c1e1ff323a2f96141c05f69278f830c5 (refs/remotes/svn/trunk)
      Found possible branch point: https://pl6.projectlocker.com/JournalDev/JDProject/svn/trunk => https://pl6.projectlocker.com/JournalDev/JDProject/svn/branches/MyDevBranch, 4
      Found branch parent: (refs/remotes/svn/MyDevBranch) f9863ff1c1e1ff323a2f96141c05f69278f830c5
      Following parent with do_switch
      Successfully followed parent
      r5 = fd5f535cf5d467df014e621ae48c22a1b7c568fa (refs/remotes/svn/MyDevBranch)A  branch_file.txt
      r6 = a04dc2dfe83419ece649d9d192406f01214bd5ab (refs/remotes/svn/MyDevBranch)
      Found possible branch point: https://pl6.projectlocker.com/JournalDev/JDProject/svn/branches/MyDevBranch => https://pl6.projectlocker.com/JournalDev/JDProject/svn/tags/MyDevBranch-1.0, 6
      Found branch parent: (refs/remotes/svn/tags/MyDevBranch-1.0) a04dc2dfe83419ece649d9d192406f01214bd5ab
      Following parent with do_switch
      Successfully followed parent
      r7 = f84c0a289589976fe8c879868626a096e36c98ef (refs/remotes/svn/tags/MyDevBranch-1.0)
      Checked out HEAD:https://pl6.projectlocker.com/JournalDev/JDProject/svn/trunk r4
      $
    4. 将分支和标签推送到远程Git存储库 :您会注意到svn2git已经创建了Git分支和标签供您推送到远程。 只需添加远程源,然后将您想要的任何分支和标签推送到远程存储库即可。

    而已。 我们已经使用svn2git工具将SVN信息库迁移到Git。 svn2git可以使用多种选项,例如–notags(如果您不想迁移标签)。 请浏览svn2git用法部分以了解各种选项。 还要注意,不是标准svn结构一部分的README.txt文件不会被迁移。

    这就是svn到git迁移的全部。 基于以上分析,对我来说svn2git工具似乎比git svn clone native命令更好。

  • 翻译自: https://www.journaldev.com/10618/svn-to-git-migration-complete-tutorial

    svn迁移到git

svn迁移到git_SVN到GIT的迁移完整教程相关推荐

  1. gerrit 数据迁移_详解git仓库迁移的两种解决方案

    Git仓库迁移而不丢失log的方法 要求能保留原先的commit记录,应该如何迁移呢? 同时,本地已经clone了原仓库,要配置成新的仓库地址,该如何修改呢? 注意:如果使用了代码审核工具Gerrit ...

  2. 两个git库之间迁移_从一个git仓库迁移代码到另一个git仓库(亲测有效版)(转)...

    不保留log等提交的记录的迁移就不说了,soeasy!代码复制粘贴就可以 目标:把A仓库的代码迁移到B仓库并且保存所有的git log,B仓库已经存在了哦,哪怕是个空仓库. 再说这个之前先说点其他.在 ...

  3. git/github使用完整教程(2)分支

    分支 首先,我们创建dev分支,然后切换到dev分支: $ git checkout -b dev Switched to a new branch 'dev' git checkout命令加上-b参 ...

  4. git/github使用完整教程(1)基础

    安装git 在Linux上安装Git 首先输入git,看看系统有没有安装Git: $ git The program 'git' is currently not installed. You can ...

  5. svn 提交到远程仓库_聊聊如何从SVN迁移源码到Git仓库

    背景介绍 这里就不再赘述关于SVN与Git的区别以及为什么要迁移源码到Git了,毕竟Git是当前的主流DVCS了,而且已经公认地非常好用,如果你还在使用SVN的话该考虑换了,是时候迁移那些遗留代码了, ...

  6. git仓库迁移和更新远程仓库地址

    git仓库迁移和更新远程仓库地址 一.git仓库迁移 1,从原仓库clone或pull到本地仓库 git clone project_name ​[old_remote_repository_addr ...

  7. git log 迁移_现场故事:从Log4J迁移到Log4J2

    git log 迁移 通过从您的应用程序学习企业APM产品,发现更快,更有效的性能监控. 参加AppDynamics APM导览! 与许多Java应用程序一样,AppDynamics Java代理广泛 ...

  8. git仓库迁移(阿里云git切换到公司内部的gitlab)

    项目刚开始做的时候,因为公司内部的git服务器尚未搭建好,所以使用了阿里云git服务器,目前内部服务器已搭建好,所以git需要完整迁移(完整迁移,就是指,不仅将所有代码移植到新的仓库,而且要保留所有的 ...

  9. 个人总结出来的git仓库迁移方案

    git仓库迁移方案 要求:所有远程分支和提交记录都要迁移 情况1: 单人项目 步骤: 1.git clone --bare 原仓库 (从原地址克隆一份裸版本库) 2.git push --mirror ...

最新文章

  1. python 装饰器 参数-python装饰器的详细解析
  2. linux启动java包脚本
  3. 敏捷软件开发实践-Sprint Status Track
  4. 关于开源分布式事务中间件Fescar,我们总结了开发者关心的13个问题
  5. matlab 信号分选 聚类_显示微缩化,对测试分选设备提出了怎样的要求?
  6. 推荐12个漂亮的CSS3按钮实现方案
  7. 以太坊的POS共识机制友善的小精灵 Casper
  8. [BZOJ5109/CodePlus2017]大吉大利,晚上吃鸡!
  9. 参考三:容易误解读的量子擦除实验
  10. archpr说文件不是rar文件_PDF压缩 | 从此PDF“文件过大”再也不是难题
  11. 使用spring-data-redis实现incr自增
  12. Python_文本分析入门_SnowNLP(1)
  13. 数控车椭圆编程实例带图_简析数控车床上椭圆加工的编程方法
  14. 转载给浮躁的软件业同仁 (作者不是我,但是确实是好文)
  15. 红日ATTCK实战系列(一)
  16. FreeLaunchBar-Windows10系统任务栏快捷方式管理者
  17. Linux桌面差,六种 Linux 桌面的最佳特性和最差特性
  18. chatgpt赋能python:Python怎么接单子平台有哪些
  19. java 面试题详解(转自传智播客张孝祥老师)
  20. winform的Textbox设置只读之后ForeColor无效的解决方法

热门文章

  1. 软件工程实验一--编程随机生成30个四则运算,算数包括100以内的整数和真分数。...
  2. dynamic结合匿名类型 匿名对象传参
  3. asp.net 导出word文档
  4. 程序员和美工是否可共存?
  5. [转载] Java static关键字详解
  6. vivado中FIFO IP核的Standard FIFO和First-word-Fall-Through模式的仿真比较
  7. elasticsearch-head的使用
  8. git 常用命令及虚拟机服务器仓库搭建
  9. kubernetes1.4新特性:支持两种新的卷插件
  10. 【转】基于Ubuntu 14.04 LTS编译Android4.4.2源代码