我遇到了this mailing list post中描述的问题。当还原提交之后是合并提交时,‘'git子树拆分’无法重建历史记录。我稍微调整了Fabien在他的邮件列表帖子中提供的测试脚本:
git init
# create a directory that is going to be split
mkdir doc
echo "TEST" > doc/README
git add doc
# commit A
git commit -a -m"first version"
# create a branch with a new commit (Z)
git checkout -b test
echo "TEST" > doc/README1
git add doc/README1
git commit -a -m"added README1"
git checkout master
# modify the README file (commit B)
echo "TEST_" > doc/README
git commit -a -m"second version"
# revert the change (commit C)
echo "TEST" > doc/README
git commit -a -m"revert second version"
# or use git revert HEAD^
# split
git subtree split --prefix="doc" --branch=TARGET
# add another commit (to a file *not* in the subtree dir)
echo "BLA" > BLA
git add BLA
git commit -a -m"third version"
# adding another commit to a file in the subtree dir will "fix" things
#echo "MEH" > doc/MEH
#git add doc
#git commit -a -m"fourth version"
# the log will show the 3 commits as expected (including B and C)
GIT_PAGER= git log --oneline TARGET
# merge the test branch
git merge -m"merged test" test
# attempt to re-split; this will fail
git subtree split --prefix="doc" --branch=TARGET
# see what history split generates
git subtree split --prefix="doc" --branch=TARGET2我发现,如果还原提交之后是另一个在子树目录中进行更改的提交,则拆分将按预期工作(请参阅上面的“第四版”)。这看起来像是git-subtree中的一个bug。
然而,在我的例子中,合并当然已经执行了,所以我不能通过添加一个虚拟提交来修复问题。有没有别的办法来解决这个问题呢?也许是git-subtree源代码的快速修复补丁?
发布于 2013-08-27 21:55:45
我想我明白是怎么回事了。如果两个分支中的一个分支中没有净更改,则合并提交的id将与另一个分支上最后一次提交的id相同(将-d选项传递给git subtree split命令以查看拆分出的提交的新提交id)。在这种情况下,git-subtree将删除合并提交。这样做是因为对于常规提交,这意味着提交不会对子树目录中的文件进行更改。
我认为解决方案应该是简单地调整copy_or_skip函数,使其始终复制合并提交。然而,这可能会导致生成的提交历史与以前不同(以前忽略了不必要的合并提交),从而导致其他问题。
https://stackoverflow.com/questions/18465867
复制相似问题