git subtree merge 和 git-subtree 有什么区别?

15

我刚刚发现git-subtree工具,它在一段时间前成为了主git代码库的一部分 https://github.com/apenwarr/git-subtree/

然而,我并不完全理解这个工具提供了什么功能,相比于已经存在的“git read-tree”+ “git merge -s subtree”。git-subtree的唯一目的是使最终提交历史看起来更好,还是有其他的功能我忽略了呢?

3个回答

12

您描述的命令将子树读入存储库中。如文档所述,git-subtree命令还有许多其他选项。其中包括(为简单起见进行了注释):

add::
    Create the <prefix> subtree by importing its contents
    from the given <refspec> or <repository> and remote <refspec>.
merge::
    Merge recent changes up to <commit> into the <prefix>
    subtree.
pull::
    Exactly like 'merge', but parallels 'git pull' in that
    it fetches the given commit from the specified remote
    repository.
push::
    Does a 'split' (see above) using the <prefix> supplied
    and then does a 'git push' to push the result to the 
    repository and refspec. This can be used to push your
    subtree to different branches of the remote repository.
split::
    Extract a new, synthetic project history from the
    history of the <prefix> subtree.  The new history
    includes only the commits (including merges) that
    affected <prefix>, and each of those commits now has the
    contents of <prefix> at the root of the project instead
    of in a subdirectory.  Thus, the newly created history
    is suitable for export as a separate git repository.

此外还有各种标志可以辅助和操作上述过程。我相信所有这些选项在之前都可以通过一系列管道命令来使用。git-subtree.sh只是将它们封装起来,使它们更容易执行。


5
如果你查看旧的子树代码,它被添加到 git 作为一个 contrib 模块之前: https://github.com/apenwarr/git-subtree/blob/master/git-subtree.sh,你可以看到 git 子树工具实际上是一个更高级的包装器,围绕着底层的 git 子树合并策略。它基本上以明智的方式利用这些策略,使子树管理变得更加容易。特别是 --squash 部分,非常有用。

1
除了具有更多选项外,git subtree 还考虑了 Git 配置。
但是关于 git subtree pull,请确保使用 Git 2.36+。
git subtree 想要创建合并时,它使用 "git merge"(man) 并让其受到最终用户的 "merge.ff" 配置的影响。这个问题已经在 Git 2.36(2022 年第二季度)得到了修正。
查看 提交9158a35(2022年2月1日),作者是Thomas Koutcher(koutcher
(由Junio C Hamano -- gitster --提交0ac270c中合并,于2022年2月17日)

subtree:强制合并提交

签署者:Thomas Koutcher
审查者:Johannes Altmanninger

When merge.ff is set to only in .gitconfig, git subtree pull will fail with error

fatal: Not possible to fast-forward, aborting. 

But the command does want to make merges in these places.

Add --no-ff argument to git merge(man) to enforce this behaviour.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接