简体   繁体   English

将在 git 存储库中的子项目中增长的基础项目合并,除了 git submodule 或 subtree 合并方法

[英]Combine a base project that is growing in child projects in git repository except git submodule or subtree merge methods

There are some child projects: "Project 1", "project 2" and so on in the future.未来有一些子项目:“项目1”,“项目2”等等。

Also, There is a project that named: "Base Project" and it's foundation of other projects.此外,还有一个名为“Base Project”的项目,它是其他项目的基础。 "Base Project" is a content management system (CMS). “Base Project”是一个内容管理系统(CMS)。

All projects have their own git repositories.所有项目都有自己的 git 存储库。

"Project 1" , "project 2" and others uses "Base Project" to develop and grow. “项目1”、“项目2”等利用“基础项目”发展壮大。

There are some methods in git like submodule or subtreemerge. git 中有一些方法,如 submodule 或 subtreemerge。 but don't seem to fit here.但似乎不适合这里。 "Base Project" not should be clone into a sub directory. “基础项目”不应克隆到子目录中。 It's in root directory.它在根目录中。 It's growing in "project 1" or "project 2"...它在“项目 1”或“项目 2”中增长......

When I work in child projects, I have to be able to push "Base Project" changes separately to It's own repository to fetch in other children.当我在子项目中工作时,我必须能够将“基本项目”更改单独推送到它自己的存储库以获取其他子项。

What can I do?我能做什么?

Subtree merge or submodules are for a component-based development : two different but coherent set of files combined together.子树合并或子模块用于基于组件的开发:组合在一起的两个不同但一致的文件集。
Each set of files is in its own directory, because they can be branched or labelled independently (submodules), or together (subtree merge, while keeping the ability to get back an history of their own).每组文件都在自己的目录中,因为它们可以独立(子模块)或一起(子树合并,同时保持获取自己的历史记录的能力)分支或标记。
Both are requiring a separate directory though.两者都需要一个单独的目录。

But what you are describing (" Base Project " is in root directory, growing in " project 1 " or " project 2 ") is about a system-based approach : all components merged into one large component: one large set of file which will always evolve together, as one unit.但是您所描述的(“ Base Project ”在根目录中,在“ project 1 ”或“ project 2 ”中增长)是关于一种基于系统的方法:所有组件合并到一个大组件中:一组大文件永远一起进化,作为一个整体。
So you can have one branch per project: branch1 for CMS-projet1 , branch2 for CMS-project2 , and so on.所以,你可以为每个项目的一个分支: branch1CMS-projet1branch2CMS-project2 ,依此类推。

But if you need to report projectx -specific modifications or CMS-specific modifications back to their original (and separate) repos, then make said specific changes in dedicated branches, and then combine those changes :但是,如果您需要将特定于projectx修改或特定于 CMS 的修改报告回其原始(和单独的)存储库,则在专用分支中进行所述特定更改,然后组合这些更改

  • branchp1 would be for changes affecting project1 branchp1将用于影响project1更改
  • branchc1 would be for changes affecting CMS branchc1将用于影响CMS更改
  • branch1 would be the result of the merge from branchp1 and branchc1 branch1将是branchp1branchc1合并的结果

(same thing for branch2 ) (对于branch2

You can then export those changes as patches :然后,您可以将这些更改导出为补丁

  • from branchp1 to project1 repobranchp1project1 branchp1
  • from branchc1 to CMS repobranchc1CMS

The inconvenient is that Git won't remember what has already been merged back to the original repos, but that would allow you to report the common history developed in your CMS-projectx set of files back to your original CMS and projectx repos.不便之处在于 Git 不会记住已经合并回原始存储库的内容,但是这将允许您将在CMS-projectx文件集中开发的公共历史记录报告回原始CMSprojectx库。


Note: if you don't want to manage 2 extra branches, another solution is to:注意:如果您不想管理 2 个额外的分支,另一种解决方案是:

  • make sure each commit only include CMS modification OR project modification确保每次提交只包括 CMS 修改或项目修改
  • leave a commit message which helps to distinguish them (" [CMS] my CMS modification comment... ", or " [Project1] my project1 modification comment... "留下有助于区分它们的提交消息(“ [CMS] my CMS modification comment... ”,或“ [Project1] my project1 modification comment...
  • use the script git-extract-patches to export as patches only the right commits.使用脚本git-extract-patches patches 仅将正确的提交导出为补丁。

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

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