如何使用git仓库组织跨项目的共享代码/资产 [英] How to organize shared code/assets across projects with git repositories

查看:164
本文介绍了如何使用git仓库组织跨项目的共享代码/资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方案,其中基础项目由Java代码和网站文件(jsp/html/javascript,模板,css,图像等)组成.

I have a scenario where the base project consists of java code and web site files (jsp/html/javascript, templates, css, images etc).

创建此基础项目的变体的原因如下:

Variants of this base project are created for the following reasons:

a)白色标签+自定义

a) white labelling + customization

b)基于该项目的新项目,但具有其他功能(包括Java和Web文件)

b) A new project based on this project but additional features (both in java and web files)

基础项目
Java

Base project
java

  • src/core

网络

  • 模板

  • templates

css

javascript

javascript

图片

项目A(基于基准)
Java

Project A (based on the base)
java

  • src/core

  • src/core

src/projectA特定文件夹

src/projectA specific folders

网络

  • 模板

  • templates

css

javascript

javascript

图片

projectA特定文件夹

projectA specific folders

项目B(基于基准)
Java

Project B (based on the base)
java

  • src/core

  • src/core

src/projectB特定的文件夹

src/projectB specific folders

网络

  • 模板

  • templates

css

javascript

javascript

图片

projectB特定文件夹

projectB specific folders

重要约束

a)projectA和projectB都共享基础项目中的很多代码

a) Both projectA and projectB share quite a bit of code from base project

b)除了拥有自己的文件和代码外,ProjectA和ProjectB还可以在web/模板,web/css,web/图像文件夹中添加,修改或删除文件-用于自定义和白色标签

b) In addition to having their own files and code, ProjectA and ProjectB could add, modify or delete files in web/templates, web/css, web/image folders - for customization and white labelling

c)将来可以创建更多项目,例如projectA和projectB

c) More projects like projectA and projectB could be created in the future

d)更改基础项目时,应该可以将更改反映回子项目中

d) When base project is changed, it should be possible to have the changes reflected back in sub-projects

e)有时,在projectA/projectB中对通用文件所做的更改应折回到基础项目中.

e) Occasionally, changes made in projectA/projectB to common files should be folded back into base project.

最初,我以为我将为基础项目以及项目A,B等每个项目创建单独的git存储库.但是要特别注意上述约束,在我看来git子树或子模块方法都不起作用(对于明显的局限性)

Initially, I thought I will have separate git repository for base project and each of Project A, B etc. But keeping particularly the above constraints in mind, It looks to me that both git subtree or submodule approaches do not work(for obvious limitations)

因此,我倾向于使用单个存储库,并使用分支"方法,其中projectA和projectB将成为分支,而base将成为主".约束(e)在这种方法中的效果如何?

So, I am tending towards having a single repository and using "branching" approach where projectA and projectB will be branches and base will be the "master". How well does constraint (e) work in this approach ?

是否有更好的方法在git中进行管理?

Are there better ways of managing this in git ?

推荐答案

您为每个子项目设置一个base分支和一个分支的方法听起来很合理.

Your approach of having a base branch and a branch for each subproject sounds reasonable.

然后,您可以从子项目中检出basecherry-pick需要合并的提交(约束e).

Then you can checkout base and cherry-pick the commits you need to incorpore from your subproject (constraint e).

这篇关于如何使用git仓库组织跨项目的共享代码/资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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