简体   繁体   English

在不同存储库中拆分git存储库以减小大小

[英]Split git repository in different repositories to reduce size

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. 除了通常的commit/pull/push/branch等命令之外,我对git的了解也不是很熟练,所以我不知道搜索所需的正确单词。

I'm looking for advice on how to get to what I want and pointers to URLs and such that give more explanation. 我正在寻找有关如何获得所需内容以及指向URL的指针的建议,以便给出更多说明。

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. 每个子产品都有其自己的子目录树,但是用于构建子产品和最终产品的Jenkins作业仍将整个存储库中的内容仅用于构建应做的一个产品。

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. 我已经读过git-subtree可以解决这个问题,但我从未使用过。

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 . 为此,请使用此文件夹bfc In your case simply clean out the subfolders which you are changing to be submodules . 在您的情况下,只需清除要更改为submodulessubfolders

在此处输入图片说明

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

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