从 svn 移动到 git 时保留所有历史记录

Keeping all history when moving from svn to git

从 svn 迁移到 git 时是否可以保留所有历史记录? 我发现 svn copy 之前的历史记录丢失了。

我有以下 svn 存储库:

如果我git svn clone project3,project1 和project2 中没有A 和B 的历史。

下面是问题的演示:

> svn co https://localhost/svn/test
> cd test
> mkdir -p project1/trunk project1/branches project1/tags
> mkdir -p project2/trunk/dir project2/branches project2/tags
> mkdir -p project3/trunk project3/branches project3/tags
> touch project1/trunk/A project2/trunk/dir/B
> svn add project1 project2 project3
> svn ci -m 'initial commit'
> svn copy project1/trunk/A project3/trunk/
> svn copy project2/trunk/dir project3/trunk/
> svn ci -m 'project restructure'

运行 svn log 显示两个版本:

> svn log project3/trunk/A 
 ------------------------------------------------------------------------
 r2 | tanderson | 2015-04-16 19:37:33 +1000 (Thu, 16 Apr 2015) | 1 line

 project restructure
 ------------------------------------------------------------------------
 r1 | tanderson | 2015-04-16 19:37:32 +1000 (Thu, 16 Apr 2015) | 1 line

 initial commit
 ------------------------------------------------------------------------
> svn log project3/trunk/dir/B 
 ------------------------------------------------------------------------
 r2 | tanderson | 2015-04-16 19:37:33 +1000 (Thu, 16 Apr 2015) | 1 line

 project restructure
 ------------------------------------------------------------------------
 r1 | tanderson | 2015-04-16 19:37:32 +1000 (Thu, 16 Apr 2015) | 1 line

 initial commit
 ------------------------------------------------------------------------

现在克隆:

> git svn clone --stdlayout --follow-parent https://localhost/svn/test/project3 gittest
  Using higher level of URL: https://localhost/svn/test/project3 => https://localhost/svn/test
  r1 = 1bc0768d6d823b49305978d227df6834d2787fdc (refs/remotes/origin/trunk)
       A       A
       A       dir/B
  r2 = c71c15ec116a7ada952d8457d50902c970616ef5 (refs/remotes/origin/trunk)
  Checked out HEAD:
      https://localhost/svn/test/project3/trunk r2

我希望看到 A 和 B 的两个修订版,但在这两种情况下都只显示最终修订版。例如

> cd gittest
> git log --follow A
   commit c71c15ec116a7ada952d8457d50902c970616ef5
   Author: tanderson <tanderson@897fde24-c897-6841-ad7f-93f2e7295302>
   Date:   Thu Apr 16 09:37:33 2015 +0000

    project restructure

    git-svn-id: https://localhost/svn/test/project3/trunk@2 897fde24-c897-6841-ad7f-93f2e7295302

我试过以下工具:

是的,可以。有用于此目的的工具。

一个常用工具是https://github.com/nirvdrum/svn2git。它将完整的 svn 历史翻译成 git.

在上面的简单测试存储库中,svn-all-fast-export 有效。

它是用 C++ 编写的,没有二进制文件。我能够使用 cygwin 构建它。

要隐藏上面的示例 svn 存储库:

  1. 在本地复制 svn 存储库(使用 svnadmin hotcopy 或 svnsync)
  2. 根据 https://git-scm.com/book/en/v2/Git-and-Other-Systems-Migrating-to-Git
  3. 创建作者文件 users.txt
  4. 创建规则文件,rules.txt 指示 svn-fast-all-export 如何处理存储库路径:

    create repository testnew
    end repository
    
    match /project1/trunk/
        repository testnew
        branch project1
    end match
    
    match /project2/trunk/
        repository testnew
        branch project2
    end match
    
    match /project3/trunk/
        repository testnew
        branch master
    end match
    
  5. 运行:

    svn-all-fast-export --identity-map=users.txt --rules=rules.txt --stats /path/to/repo/test.svn
    

这将在当前目录中创建一个 git 存储库 testnewgit log 命令显示 A 和 B 的两个修订版。例如:

> git log A
  commit eb561b48109620fc64f9f7cf15a752b1730f8d18
  Merge: e3a02bf e1cc2a9
  Author: tanderson <tanderson@localhost>
  Date:   Sun May 24 06:00:36 2015 +0000

     project restructure

  commit e3a02bff6a7ace21b3789c4f9350e969add44541
  Author: tanderson <tanderson@localhost>
  Date:   Sun May 24 06:00:35 2015 +0000

     initial commit