在Git中管理一组相关的相对存储库 [英] Managing a set of related repositories relative in Git

查看:62
本文介绍了在Git中管理一组相关的相对存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组要管理的相关存储库.

我要存储的数据是由库"组成的项目",库"由单元"组成. 每个库都存储在项目的子文件夹中,每个单元都存储在库的子文件夹中.

为了能够在多个项目之间重用库和单元,我计划根据以下方案存储它们:

repositories/projects/project1
repositories/projects/project2>
repositories/projects/project...
repositories/libraries/library1
repositories/libraries/library2
repositories/libraries/library...
repositories/units/unit1
repositories/units/unit2
repositories/units/unit...

我想相对地引用项目中使用的库(例如使用../../libraries/library1),也要相对地引用库中的一个单元.

只能通过修改包含库和单元的项目来对其进行修改.因此,如果有必要,库和单位存储库可能会光秃秃的.

服务器上的存储库应该看起来相同(文件夹的布局相同).

我已经尝试过使用子模块和读取树/子树合并"方法,但是找不到在子模块的情况下为存储库指定相对URL并在读取树方法中推送更改的方法. /p>

我想要完成的是,如果我检出project1,它还将获取所有必需的库和单元,并且如果我通过项目更改一个库或单元,这些更改可以轻松地再次推送到服务器.

解决方案

子模块是您的理想之选,并且允许相对URL.

一个子模块可以指定相对于超级项目的origin URL的另一个子模块URL.因此,在project1中,使用以下

git submodule add ../library1
git submodule --init update

应该没问题:library1将在project1的目录中检出,其原始存储库位于project1旁边.

I have a set of related repositories that I want to manage.

The data I want to store are "projects" that consist of "libraries" which consist of "units". Each library is stored in a subfolder of the project, and each unit is stored in a subfolder of a library.

To be able to reuse libraries and units between several projects I plan to store them according to this scheme:

repositories/projects/project1
repositories/projects/project2>
repositories/projects/project...
repositories/libraries/library1
repositories/libraries/library2
repositories/libraries/library...
repositories/units/unit1
repositories/units/unit2
repositories/units/unit...

I'd like to reference the libraries used in a project relatively (say uses ../../libraries/library1) and to reference a unit in a library also relatively.

Libraries and units can only be modified by modifying a project containing them. So the library and unit repositories could be bare if it's necessary.

The repository on the server should look the same (same layout of folders).

I've already tried using submodules and the "read-tree/subtree merge" approach but couldn't find a way to specify relative urls to repositories in the submodule case and to push changes in the read-tree approach.

What I'd like to accomplish is that if I check out project1, it also fetches all libraries and units necessary and if I change a library or unit through a project these changes can be easily pushed to the server again.

解决方案

Submodules are the way to go for you, and allow relative URLs.

A submodule can specify another submodule URL relative to the superproject's origin URL. So in project1, use the following

git submodule add ../library1
git submodule --init update

And it should be fine: library1 will be checked out in project1's directory, its original repo being next to project1.

这篇关于在Git中管理一组相关的相对存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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