git submodule 和 subtree 的区别 [英] Differences between git submodule and subtree

查看:32
本文介绍了git submodule 和 subtree 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 git submodule 和 subtree 有什么概念上的区别?

What are the conceptual differences between using git submodule and subtree?

每种情况的典型场景是什么?

What are the typical scenarios for each?

推荐答案

  • submodule 更适合基于组件的开发,您的主要项目取决于在另一个组件的固定版本(repo)上.
    您只保留父存储库中的引用(gitlinks索引中的特殊条目)
    • submodule is a better fit for component-based development, where your main project depends on a fixed version of another component (repo).
      You keep only references in your parent repo (gitlinks, special entries in the index)
    • 如果我希望链接始终指向外部存储库的 HEAD 怎么办?

      What if I want the links to always point to the HEAD of the external repo?

      你可以创建一个子模块来跟随子模块远程仓库的一个分支的 HEAD,使用:

      You can make a submodule to follow the HEAD of a branch of a submodule remote repo, with:

      o git submodule add -b <存储库>[<路径>].(指定要遵循的分支)
      o git submodule update --remote 它将子模块的内容更新到 / 的最新 HEAD,默认为 origin/主.即使使用了 --remote,您的主项目仍将跟踪子模块的 HEAD 的哈希值.

      o git submodule add -b <branch> <repository> [<path>]. (to specify a branch to follow)
      o git submodule update --remote which will update the content of the submodule to the latest HEAD from <repository>/<branch>, by default origin/master. Your main project will still track the hashes of the HEAD of the submodule even if --remote is used though.

      • subtree is more like a system-based development, where your all repo contains everything at once, and you can modify any part.
        See an example in this answer.

      另外,正如 philb评论git subtree 是一个 contrib/,而不是 git submodule(核心命令)

      Plus, as noted by philb in the comments, git subtree is a contrib/, as opposed to git submodule (core command)

      这篇关于git submodule 和 subtree 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆