我遇到了这个邮件列表帖子中描述的问题。当还原提交后跟合并提交时,“git subtree split”无法重建历史记录。我稍微调整了 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 中的错误。
但是,就我而言,当然已经执行了合并,因此我无法通过添加虚拟提交来解决问题。有没有其他方法可以解决这个问题?也许是 git-subtree 源代码的快速修复补丁?