git Git子模块或子存储库或远程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5437460/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:14:34  来源:igfitidea点击:

Git submodule or sub-repository or remote?

gitmodulecode-organizationproject-organization

提问by FMaz008

I'm using GIT to manage a Content Management System (CMS) project. The CMS can have multiple plugin (module).

我正在使用 GIT 来管理内容管理系统 (CMS) 项目。CMS 可以有多个插件(模块)。

So basically, I want to have 3 types of repositories:

所以基本上,我想要 3 种类型的存储库:

  • The core CMS development ( every new project is a checkout of that last stable & unconfigured version )
  • 1 repository per module/plugin. ( every new project will checkout the last stable version of the module they want to implement )
  • 1 repository per project ( each client will be a repository that represent the personalization from the core CMS and the modules )
  • 核心 CMS 开发(每个新项目都是最后一个稳定和未配置版本的检出)
  • 每个模块/插件 1 个存储库。(每个新项目都会检查他们想要实现的模块的最后一个稳定版本)
  • 每个项目 1 个存储库(每个客户端将是一个存储库,代表来自核心 CMS 和模块的个性化)

For the type 1 & 2, I guess it's simple basic repository. But when it come to client project, I get confused:

对于类型 1 和 2,我猜它是简单的基本存储库。但是当涉及到客户项目时,我感到困惑:

  • First I'll clone the CMS, then go in the /modules/ folder and clone again all required modules ? That will make a repository inside a repository ! Will the first repo will try to log the .git/ folder of each module ?
  • I can't use submodule as each client needs their modules to be personalized.
  • If I modify a core component of a module ( not a personalization, just a bug fix ), can I push that single file to the original module repository ?
  • (Not talking of the module unitTest that will be spread all around )
  • 首先我将克隆 CMS,然后进入 /modules/ 文件夹并再次克隆所有需要的模块?这将在存储库中创建一个存储库!第一个 repo 会尝试记录每个模块的 .git/ 文件夹吗?
  • 我不能使用子模块,因为每个客户都需要对他们的模块进行个性化。
  • 如果我修改了一个模块的核心组件(不是个性化,只是一个错误修复),我可以将该单个文件推送到原始模块存储库吗?
  • (不是在谈论将四处传播的模块 unitTest )

So the question is: How should I organize the repository(s) / files / folders in order to be efficient ?

所以问题是:我应该如何组织存储库/文件/文件夹以提高效率?

采纳答案by John Douthat

The layout you've described will work really well with git submodules. I'd gently recommend reading the docsand trying a few tutorials. The key difference your plan introduces is that each client repository and client plugin repository will have two remotes instead of one. And, when you want to start a new client project you will need to

您所描述的布局非常适合 git 子模块。我建议您阅读文档并尝试一些教程。您的计划引入的主要区别在于,每个客户端存储库和客户端插件存储库将有两个远程而不是一个。而且,当您想开始一个新的客户项目时,您需要

  1. fork the mainline cms
  2. fork all of the plugins that will be modified
  3. clone the forked cms from (1), update its submodules to point to the new remotes from (2)
  4. initialize/update the submodules
  5. (optional) add the mainline cms URL as a remote in your client's forked cms
  6. (optional) add the mainline plugin URLs as remotes in your client's forked plugins
  1. fork 主线 cms
  2. fork 将要修改的所有插件
  3. 从 (1) 克隆分叉的 cms,更新其子模块以指向 (2) 中的新遥控器
  4. 初始化/更新子模块
  5. (可选)在客户端的分叉 cms 中添加主线 cms URL 作为远程
  6. (可选)在客户端的分叉插件中添加主线插件 URL 作为远程

A better option may be to use the same repository and simply make a branch per client. That is how I would do it.

更好的选择可能是使用相同的存储库并简单地为每个客户端创建一个分支。这就是我要做的。

回答by Maxime Brehin

Short update / additional information about the previous answer: if you don't like git submodulesapproach or think this is too hard to understand, you can try

关于上一个答案的简短更新/附加信息:如果您不喜欢git submodules方法或认为这太难理解,您可以尝试

Don't forget to check if you can use another depency manager (like RubyGems for Ruby, Composer for PHP...) instead of submodules, it would be easier to use and maintain.

不要忘记检查您是否可以使用另一个依赖管理器(例如 RubyGems for Ruby,Composer for PHP...)而不是子模块,它会更易于使用和维护。