git子树merge和git-subtree有什么区别

时间:2012-07-31 13:29:11

标签: git git-merge git-subtree

我刚刚发现git-subtree工具,前段时间成为主要git repo的一部分 https://github.com/apenwarr/git-subtree/

但是,我并不完全了解此工具对现有的“git read-tree”+“git merge -s subtree”提供的功能。是git子树的唯一选择 - 使得结果提交历史看起来更好还是它具有我忽略的更多功能?

2 个答案:

答案 0 :(得分:12)

您描述的命令会将子树读入存储库。 git-subtree命令有更多选项,如the documentation.所述,您可以(为简单起见注释):

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只是包装它们并使它们更容易执行。

答案 1 :(得分:5)

如果您在将旧子树代码添加到git作为contrib模块之前查看它:https://github.com/apenwarr/git-subtree/blob/master/git-subtree.sh您可以看到git子树工具实际上是围绕较低级别git子树合并策略的更高级包装器。

它基本上以合理的方式利用这些策略,使子树管理变得更加容易。特别是--squash的东西真的非常有用。