我正在根据这个答案迁移我的SVN存储库.一切顺利,但最后我没有完整的历史.我可以跟踪问题的根源到我做的"SVN移动".
这就是我所做的:一开始我的SVN回购没有trunk branches tagsdirs.当我介绍它们并将所有内容移动到主干中时(然后我创建了一个分支,这就是我决定引入新文件夹结构的原因).
因此,在将SVN repo迁移到git之后,只有引入新文件夹结构后的历史记录可用.
我在一个非常简单的场景中重现了这个问题.
SVN的历史:

git的历史:

包含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
Run Code Online (Sandbox Code Playgroud)
(在完整的非 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.
Run Code Online (Sandbox Code Playgroud)
请注意,在 stdlayout 存储库中,提交d403c6c是 tree d6c0d6c,在完整克隆中,提交37d77b8及其父级3a47847也具有相同的树。一开始你可能会觉得这很奇怪,直到你意识到在 git-svn 克隆中创建 /trunk /branches /tags 实际上是一个空操作,因为 Git 不跟踪空目录。
在 stdlayout 存储库中,您可以导入完整克隆的非标准克隆:
# git remote add fullclone ../fullclone
# git fetch fullclone
Run Code Online (Sandbox Code Playgroud)
然后从完整存储库的“新文件夹结构”提交中签出一个新分支:
# git checkout -b fix-history 37d77b8
Run Code Online (Sandbox Code Playgroud)
然后在标准布局存储库中重播从此时开始的所有提交:
# git cherry-pick d403c6c..master
Run Code Online (Sandbox Code Playgroud)
如果您有许多重组后提交,这可能需要一段时间才能运行,因为每个提交都会在新分支上重新提交。结果应该是重组前后主干的历史记录。