【问题标题】:How to work around 'git subtree split' failing on revert commits?如何解决“git subtree split”在还原提交时失败的问题?
【发布时间】:2013-08-27 12:47:32
【问题描述】:

我遇到了this mailing list post 中描述的问题。当还原提交后跟合并提交时,“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 源代码的快速修复补丁?

【问题讨论】:

    标签: git git-subtree subtree


    【解决方案1】:

    我想我明白发生了什么。如果两个分支之一没有净变化,则合并提交的 id 将与另一个分支上的最后一次提交的 id 相同(将-d 选项传递给git subtree split 命令以查看新提交拆分提交的 ID)。在这种情况下, git-subtree 将删除合并提交。这样做是因为对于常规提交,这意味着提交不会更改子树目录中的文件。

    我认为解决方案是简单地调整 copy_or_skip 函数以始终复制合并提交。但是,这可能会导致生成的提交历史记录与以前不同(以前忽略了不必要的合并提交),从而导致其他问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-24
      • 2017-04-02
      • 2013-07-27
      • 2012-12-05
      • 2021-12-26
      相关资源
      最近更新 更多