将git存储库分割到不同的存储库中以减小大小 [英] Split git repository in different repositories to reduce size

查看:141
本文介绍了将git存储库分割到不同的存储库中以减小大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了通常的 commit / pull / push / branch 等命令之外,我不太熟练git,所以我不知道我需要的恰当的词搜索我想要做的事情。



我正在寻找关于如何获得我想要的建议以及指向URL的指示,并给出更多解释。



随着时间的推移,一个项目已经从单一产品发展到几个用于构建最终产品的子产品。每个子产品都有它自己的子目录树,但构建子产品的Jenkins作业和最终产品仍然拉入整个存储库,只是为了构建它应该做的一个产品。

即使对于长时间不会有太大变化的小产品,这也需要相当长的时间。所以我正在考虑将每个项目分成自己的存储库。同时,他们都遵循类似的模式来处理多个文件,所以我想将其转换为所有人使用的通用代码。这里是一个原理图布局

  / project 
/ subproject1
/ common
/ src
/ test
/ subproject2
/ common
/ src
/ test
/ common#main project
/ src#main project
/ test#main project

从我迄今为止阅读的内容来看,我认为最好的做法是是将所有子项目和主项目拆分为不同的存储库。保留历史记录会很好,但过去承诺已跨越多个子项目,并且没有使用分支机构,因此可能不可行。



另外,当我将常用代码移入其自己的存储库时,如何将文件恢复到通用目录中,以便推送通用代码中的更改到自己的存储库?我已经阅读了关于 git-subtree 这可以做到这一点,但我从来没有使用过。



这是最好的方式,还是有更简单的选择? 随着时间的推移,一个项目已经发展从单一产品到用于构建最终产品的多个子产品。

...

所以我正在考虑将每个项目拆分到自己的仓库中


您应该使用子模块。
$ b



子模块是另一个项目中的独立项目,可以在自己的文件夹中进行自我管理。

在你的情况下,因为你已经拥有了一个大型仓库中的代码,所以你必须把它分解成小饼ces。



使用这个文件夹


I'm not very proficient in git beyond the usual commit/pull/push/branch etc. commands, so I don't know the proper words I need to search for what I want to do.

I'm looking for advice on how to get to what I want and pointers to URLs and such that give more explanation.

Over time a project has evolved from a single product to several subproducts that are used to build the final product. Each subproduct has it's own subdirectory tree but the Jenkins jobs that build the subproducts and the final product still pull in the entire repository just to build the one product it's supposed to do.

This takes quite some build time, even for the small products that don't change a lot over time. So I'm thinking of splitting off each of the projects into its own repository. At the same time they all follow a similar pattern for several files so I'd like to move that into common code that is used by all. Here is a schematic layout

/project
  /subproject1
    /common
    /src
    /test
  /subproject2
    /common
    /src
    /test
  /common # main project
  /src    # main project
  /test   # main project

From what I've read so far I think the best thing to do is to split all subprojects and the main project into separate repositories. Preserving history would be nice, but commits have spanned multiple subprojects in the past and no branches were used, so that might not be feasible.

Also, when I move the common code off into its own repository, how do I get the files back into the common directory so that a change in the common code gets pushed to its own repository? I've read about git-subtree that could do the trick, but I've never used it.

Is this the best way forward or are there simpler alternatives?

解决方案

Over time a project has evolved from a single product to several subproducts that are used to build the final product.
...
So I'm thinking of splitting off each of the projects into its own repository

You should submodules.

Submodules is a independent project inside another project, which is self managed in its own folder.

In your case since you already have the code inside a big one repository so you will have to break it down to small pieces.

To do it use this folder bfc. In your case simply clean out the subfolders which you are changing to be submodules.

这篇关于将git存储库分割到不同的存储库中以减小大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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