且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将git子树移动到其他存储库中

更新时间:2023-02-25 20:19:13

好的,阅读源代码可以清除一切.

Alright, reading the source cleared things up.

git subtree add非常难看:它首先使用git read-tree最新版本添加到给定目录中,而没有任何历史记录.之后,它使用git commit-tree创建一个伪合并提交,以附加包含未添加前缀文件的旧历史记录.

git subtree add is pretty ugly: It first uses git read-tree to add the current version without any history into the given directory. Afterwards it uses git commit-tree to create a fake merge commit to attach the old history containing the unprefixed files.

另一方面,现在HEAD的前缀文件和HEAD ^ 2的未前缀文件应该完全相同,并且应该被--follow识别为移动.

On the other hand, now the prefixed file at HEAD and the unprefixed one in HEAD^2 should be exactly the same and should be recognized as a move by --follow.

不幸的是,它不是这样识别的.不知道为什么.

Unfortuately it is not recognized as such. No idea why.

***的解决方案可能是添加显式提交,将文件移动到新目录并进行常规合并. -一种替代方法是按照

The best solution is probably to add an explicit commit moving the files to the new directory and do a normal merge. - An alternative is to rewrite the history of the transplanted directory as described in How can I rewrite history so that all files, except the ones I already moved, are in a subdirectory?.

对于我的情况git subtree add不好,正常的git merge带有正确准备的子树似乎完全正确.

For my situation git subtree add is bad, a normal git merge with a correctly prepared subtree seems to be exactly the right thing.