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

Eug*_*ene 13 git git-merge git-subtree

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

但是我不完全理解这个工具提供了什么功能,而不是现有的"git read-tree"+"git merge -s subtree".是git子树的唯一选择 - 使得结果提交历史看起来更好还是它具有我忽略的更多功能?

Chr*_*her 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.
Run Code Online (Sandbox Code Playgroud)

还有各种标志可以帮助和操纵上述内容.我相信所有这些选项在通过管道命令链之前都可用.git-subtree.sh只是包装它们并使它们更容易执行.


Mix*_*gic 5

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

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