【问题标题】:What is the difference between git subtree merge and git-subtreegit subtree merge 和 git-subtree 有什么区别
【发布时间】:2012-07-29 06:52:58
【问题描述】:

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

但是我不完全理解这个工具在现有的“git read-tree”+“git merge -s subtree”上提供了什么功能。 git-subtree 的唯一目的是让生成的提交历史看起来更好,还是它有更多我忽略的功能?

【问题讨论】:

    标签: git git-merge git-subtree


    【解决方案1】:

    您描述的命令将子树读入存储库。 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 只是将它们包装起来,使它们更容易执行。

    【讨论】:

      【解决方案2】:

      如果您查看旧的子树代码,然后将其作为 contrib 模块添加到 git:https://github.com/apenwarr/git-subtree/blob/master/git-subtree.sh,您会发现 git subtree 工具实际上是对较低级别 git 子树合并策略的更高级包装器。

      它基本上以一种明智的方式利用这些策略来简化子树管理。特别是 --squash 的东西真的非常有用。

      【讨论】:

        猜你喜欢
        • 2015-04-20
        • 2016-01-15
        • 1970-01-01
        • 1970-01-01
        • 2020-07-22
        • 2012-02-22
        • 2013-05-15
        • 1970-01-01
        相关资源
        最近更新 更多