git - svn 到 git 迁移 : incomplete history

标签 git svn migration

我正在根据 this 迁移我的 SVN 存储库回答。 一切都很顺利,除了最后我没有完整的历史。我可以将问题的根源追溯到我所做的“SVN 移动”。

我是这样做的: 一开始我的 SVN 仓库没有 trunk branches tags 目录。有时我引入它们并将所有内容移动到主干中(然后我创建了一个分支,这就是我决定引入新文件夹结构的原因)。

因此在将 SVN 存储库迁移到 git 后,只有引入新文件夹结构后的历史记录可用。

我在一个非常简单的场景中重现了这个问题。

SVN 中的历史: enter image description here

git 中的历史: enter image description here

包含 SVN repo/git repo 的 zip:

https://www.dropbox.com/s/ecy54st05qah4up/svn_git_problem.zip?dl=0

有什么办法可以解决这个问题吗?

最佳答案

当你指定--stdlayout时,git svn clone将只关注修改路径/trunk、/branches或/tags下文件的svn提交——其他提交将被忽略。您最终仍然会得到存储库的有效克隆,但是正如您所观察到的那样,从 r1 到创建标准布局的历史记录将会丢失。由于您希望 Git 存储库在布局更改后了解主干、分支和标签,因此您仍然需要 --stdlayout,否则 git clone 将使用/trunk/branches/tags 将所有分支组合成一棵树,这不是您想要的。

如果您真的很关心布局更改前的历史记录(如果这是严格意义上的一次性迁移,在迁移到 Git 后没有 SVN 提交),您可以运行 git svn clone 两次 - 一次使用 --stdlayout 一次不使用。 stdlayout 版本将成为您的最终存储库,非 stdlayout 版本只能在迁移期间使用,以便在重组时将布局更改前的历史记录缝合在新布局下。这可以通过在重组时将所有重组后的提交挑选到存储库的快照上来完成。

一旦您克隆了这两个存储库,您会注意到在复制到新布局时,树干有一个通用的树形散列。这是一个示例(抱歉,没有使用您的存储库,因此哈希不同):

(在 stdlayout 存储库中):

# git log --pretty=raw
commit 44f2f60e00117dfd51fd7d6431b697ec0ccc863d
tree 5cf62e006bb7b58171010fc0ffaba08ca97520da
parent d403c6ce0789cf584af9abb945bcfd88721e391e
author (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411603 +0000
committer (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411603 +0000

    change 4 after folder structure & branch

    git-svn-id: http://<redacted>/trunk@9 4ed80924-4846-11e4-8279-c5809b3f22e4

commit d403c6ce0789cf584af9abb945bcfd88721e391e
tree d6c0d6cf271be5146b26781ab9bd78736d86ace3
parent 0c5873eab204942ffe56370cc6e1d31e5372da13
author (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411513 +0000
committer (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411513 +0000

    changed: moved to new folder structure

    git-svn-id: http://<redacted>/trunk@7 4ed80924-4846-11e4-8279-c5809b3f22e4

commit 0c5873eab204942ffe56370cc6e1d31e5372da13
tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
author (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411460 +0000
committer (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411460 +0000

    new folder structure

    git-svn-id: http://<redacted>/trunk@6 4ed80924-4846-11e4-8279-c5809b3f22e4

(在完整的非 stdlayout 存储库中):

commit ec52fff6ee1d65eadfa1d18aa4b74b553fc693e1
tree cfda32eb39248fa5969d15a21d2f8014189e88c2
parent 685fe9961abfee4d4913e83cf5a4a7e8d459a1a1
author (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411603 +0000
committer (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411603 +0000

    change 4 after folder structure & branch

    git-svn-id: http://<redacted>@9 4ed80924-4846-11e4-8279-c5809b3f22e4

commit 685fe9961abfee4d4913e83cf5a4a7e8d459a1a1
tree 817306fad0ed5466d877437cdda12ff39a0df725
parent 02caf52174c588f1d394815201b764f9abdaa640
author (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411565 +0000
committer (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411565 +0000

    created new branch

    git-svn-id: http://<redacted>@8 4ed80924-4846-11e4-8279-c5809b3f22e4

commit 02caf52174c588f1d394815201b764f9abdaa640
tree c041405a580beaef0a4e50923e9279e179c917a8
parent 37d77b8f1168d00b943e0bca3cab277cf89e7e84
author (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411513 +0000
committer (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411513 +0000

    changed: moved to new folder structure

    git-svn-id: http://<redacted>@7 4ed80924-4846-11e4-8279-c5809b3f22e4

commit 37d77b8f1168d00b943e0bca3cab277cf89e7e84
tree d6c0d6cf271be5146b26781ab9bd78736d86ace3
parent 3a4784719bd95af5bf59de96310a1d6a38af562e
author (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411460 +0000
committer (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411460 +0000

    new folder structure

    git-svn-id: http://<redacted>@6 4ed80924-4846-11e4-8279-c5809b3f22e4

commit 3a4784719bd95af5bf59de96310a1d6a38af562e
tree d6c0d6cf271be5146b26781ab9bd78736d86ace3
parent 2fb41dab5a7389ab32419b8b270d955631aaaefa
author (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411421 +0000
committer (no author) <(no author)@4ed80924-4846-11e4-8279-c5809b3f22e4> 1420411421 +0000

    update 4

... etc., continues.

请注意,在 stdlayout 存储库中,提交 d403c6c 是树 d6c0d6c,在完整克隆中,提交 37d77b8 及其父 code>3a47847 也有同样的树。一开始您可能会觉得这很奇怪,直到您意识到在 git-svn 克隆中创建/trunk/branches/tags 实际上是空操作,因为 Git 不跟踪空目录。

在 stdlayout 存储库中,您可以导入完整克隆的非标准克隆:

# git remote add fullclone ../fullclone
# git fetch fullclone

然后从完整仓库的“新文件夹结构”提交中 check out 一个新分支:

# git checkout -b fix-history 37d77b8

然后在标准布局 repo 中重播从此时开始的所有提交:

# git cherry-pick d403c6c..master

如果您有很多重组后的提交,这可能需要一段时间才能运行,因为每个提交都会在新分支上重新提交。结果应该是重组前后干线的拼接历史。

关于git - svn 到 git 迁移 : incomplete history,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27430297/

相关文章:

ruby-on-rails - 赫罗库:! [rejected] master -> master(非快进)

svn - 将 svn 补丁应用于 mercurial 存储库时出现的问题

java - Java 11 中的内部 API 替换

sql-server - 对现有更新的 SQL Server

git - 如何将 GitHub 存储库链接到 Google Colab 笔记本?

git - Jenkins GitHub 插件无法选择我的凭据

git - 创建存储库的快速快照(git?)

macos - SVN 不存储密码和用户名

SVN : Ignore files/folders on update

database - 南迁报错: NoMigrations exception for django. contrib.auth