简体   繁体   English

Git项目子模块组织

[英]Git project submodule organizing


I have a git project which includes submodules.我有一个包含子模块的 git 项目。 It looks something like this:它看起来像这样:

Project A项目A
---- Project B (submodule) ---- 项目B(子模块)
---- Project C (submodule) ----项目C(子模块)

Project C uses code from both Projects A and B.项目 C 使用来自项目 A 和 B 的代码。
Project B uses code from Project C.项目 B 使用项目 C 中的代码。

The problem that arises from this accursed situation is that when I want to make a pull request that contains changes that affects all the three projects, it becomes a mess to handle.这种该死的情况产生的问题是,当我想发出一个包含影响所有三个项目的更改的拉取请求时,处理起来就变得一团糟。

I wanted to know what is the best way to fix the current problem?我想知道解决当前问题的最佳方法是什么?
I thought about merging all of the projects into one but wanted to know if there is a better solution.我想将所有项目合并为一个,但想知道是否有更好的解决方案。

Thanks谢谢

Circular dependancies in projects is generally an opportunity to create problems and I recommend avoiding it.项目中的循环依赖通常是一个产生问题的机会,我建议避免它。 The exact solution is going to depend somewhat on your environment and requirements for the different projects.确切的解决方案将在某种程度上取决于您的环境和不同项目的要求。 The main question to ask yourself is:要问自己的主要问题是:

Is there a clean interface between the projects, or, can there be?项目之间是否有一个干净的接口,或者,可以有吗?

If we consider a micro service architecture then it makes sense to have a project per component with a strong interface between the components.如果我们考虑微服务架构,那么每个组件都有一个项目并且组件之间具有强大的接口是有意义的。 This means that the team on project A has a 'contract' with the team on project B.这意味着项目 A 的团队与项目 B 的团队签订了“合同”。

Without a clean interface then I would recommend compressing into a single repository.如果没有干净的界面,那么我建议压缩到单个存储库中。 The main reason here is to make it easy for the developers.这里的主要原因是让开发人员更容易。 Typically changes will be required in sync between the two projects.通常,两个项目之间需要同步更改。 Much easier to do in a single project than across multiple projects.与跨多个项目相比,在单个项目中执行要容易得多。

A couple more clues, do you always release the projects together, or can individual projects be released on their own?还有一些线索,你们总是一起发布项目,还是可以单独发布单个项目? If you always release the projects together, then I would suggest compressing into a single project.如果你总是一起发布项目,那么我建议压缩成一个项目。

If you have any follow up questions, or, more information about the projects you would like me to consider, please leave a comment.如果您有任何后续问题,或者您希望我考虑的项目的更多信息,请发表评论。

Summarizing.总结。 First initialize the local repository if you have not already done so with $git init如果您尚未使用$git init初始化本地存储库,请先$git init

Then add the remote repository:然后添加远程存储库:

$git remote add -f reponame https://github.com/username/reponame.git

combine remote repository with local将远程存储库与本地存储库相结合

$git merge reponame/master --allow-unrelated-histories

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

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