简体   繁体   English

包管理器与 Git 子模块/子树

[英]Package Manager vs. Git Submodule/Subtree

Are there any reasons to use a package manager rather than git submodules/subtrees, or vice versa?是否有任何理由使用包管理器而不是 git submodules/subtrees,反之亦然? The git solutions seem to be a lot more hassle than a simple package manager. git 解决方案似乎比简单的包管理器要麻烦得多。

Assume that the space-saving benefit of git submodules is not important.假设 git 子模块节省空间的好处并不重要。

Update: Someone added a C++ tag to this question, but I have removed it since.更新:有人在这个问题上添加了一个 C++ 标签,但我已经删除了它。 This question did not specifically pertain to C++.这个问题与 C++ 无关。 More general answers than the accepted answer are welcome.欢迎比接受的答案更一般的答案。

The git solutions seem to be a lot more hassle than a simple package manager. git 解决方案似乎比简单的包管理器要麻烦得多。

This is not about hassle .这不是麻烦

This is about two different ways to build a project:这是关于构建项目的两种不同方式:

  1. through binary dependencies, with a package manager ( Nexus , or Conan for C++ : you declare your dependencies, and the package manager fetches them and uses them during the compilation.通过二进制依赖项,使用包管理器( NexusC++ 的 Conan :您声明依赖项,包管理器获取它们并在编译期间使用它们。
    That is what a pom.xml or a npm-package.json : just one more file within your unique codebase, which will instruct the compiler to download the relevant dependencies这就是pom.xmlnpm-package.json :在您独特的代码库中再增加一个文件,它将指示编译器下载相关的依赖项
  2. through source dependencies, with Git submodules or subtrees, where you store references to other source code, import them, and recompile everything.通过依赖项,使用 Git 子模块或子树,您可以在其中存储对其他源代码的引用、导入它们并重新编译所有内容。
    For instance, if your system is composed of a front-end GUI sources and a backend sources, you could reference both repositories within one parent project repositories, combining their sources into one code base.例如,如果您的系统由前端 GUI 源和后端源组成,您可以在一个父项目存储库中引用这两个存储库,将它们的源合并到一个代码库中。

The first is good when building a system, where each part has its own release lifecycle, and you want to depend to pre-built dependencies.第一个在构建系统时很好,其中每个部分都有自己的发布生命周期,并且您希望依赖预先构建的依赖项。

The second is used when the dependencies are more tightly linked to the main program.当依赖关系与主程序更紧密地联系在一起时,使用第二个。

Or when there are no binary dependencies (which is the case, for instance, with Go and its modules ).或者当没有二进制依赖项时(例如, Go及其模块就是这种情况)。

"If the technological context allows for packaging and formal dependency management, you should absolutely go this route." “如果技术环境允许打包和正式的依赖管理,你绝对应该走这条路。”

The above is from Mastering Git submodules , which is such a well written and thought out article it deserves to be the top answer for this and many similar Stackoverflow questions.以上来自Mastering Git submodules ,这是一篇写得很好且经过深思熟虑的文章,值得成为这个问题和许多类似 Stackoverflow 问题的最佳答案。

Let me quote the part that is relevant to this question:让我引用与这个问题相关的部分:

Are they the right tool for the job?它们是完成这项工作的正确工具吗?

There are a number of situations where the physical presence of module code inside container code is mandated, usually because of the technology or framework being used.在许多情况下,模块代码在容器代码中的物理存在是强制性的,通常是因为所使用的技术或框架。 For instance, themes and plugins for Wordpress, Magento, etc. are often de facto installed by their mere presence at conventional locations inside the project tree, and this is the only way to “install” them.例如,Wordpress、Magento 等的主题和插件通常实际上只是安装在项目树内的常规位置,这是“安装”它们的唯一方法。

In such a situation, going with submodules (or subtrees) probably is the right solution, provided you do need to version that code and collaborate around it with third parties (or deploy it on another machine);在这种情况下,使用子模块(或子树)可能是正确的解决方案,前提是您确实需要对该代码进行版本控制并与第三方协作(或将其部署在另一台机器上); for strictly local, unversioned situations, symbolic links are probably enough, but this is not what this post is about.对于严格本地化、未版本化的情况,符号链接可能就足够了,但这不是这篇文章的内容。

On the other hand, if the technological context allows for packaging and formal dependency management, you should absolutely go this route instead: it lets you better split your codebase, avoid a number of side effects and pitfalls that litter the submodule space, and let you benefit from versioning schemes such as semantic versioning (semver) for your dependencies.另一方面,如果技术环境允许打包和正式的依赖管理,你绝对应该走这条路:它可以让你更好地拆分代码库,避免一些影响子模块空间的副作用和陷阱,并让你受益于版本控制方案,例如您的依赖项的语义版本控制 (semver)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM