如何在项目中使用2个GIT回购? (git子模块,子树) [英] How to use 2 GIT Repos in a Project? (git submodules, subtree)

查看:87
本文介绍了如何在项目中使用2个GIT回购? (git子模块,子树)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在一个有多个文件夹的项目中,其中一些如下:-

We are working on a project which has multiple folders some of them are as follows :-

核心
贡献
供应商
语言
皮肤
配置

Core
Contrib
Vendor
Languages
Skins
Config

我们已经在10个不同的服务器上为10个不同的客户端部署了该项目,对于所有客户端,前3个文件夹的内容都是相同的(公用),但是对于每个客户端,后3个文件夹的内容是不同的,我想知道如何我们将其保留在git中.

We have deployed the project on 10 different servers for 10 different client, the contents of the first 3 folders are same (common) for all the clients, but the contents of last 3 folders vary for each client, i was wondering how we would maintain this in git.

目前,我们有1个存储库,其中包含前3个文件夹(所有客户端通用)的代码,而其余3个文件夹的其余部分已通过使用gitignore避免了.

For the time being we have 1 repository which contains the code for the first 3 folders (common for all clients) and rest of the remaining 3 folders have been avoided by using gitignore.

我想知道我们是否可以为每个客户端建立10个配置分支或存储库,其中包含最后3个文件夹的数据(每个客户端各不相同),所以我经历了子模块和一些其他解决方案,但是仍然有人可以指导我建立一个好的架构.

I wanted to know if we can make 10 config branches or repos for each client which would contain the data for the last 3 folders (which vary for each client), i have gone through sub-modules and some other solutions, but still if someone could guide me with a good architecture for this.

推荐答案

Submodules 允许将外部存储库始终嵌入到源树的专用子目录 中指向特定的提交.

Submodules allow foreign repositories to be embedded within a dedicated subdirectory of the source tree, always pointed at a particular commit.


git submodule

按照您的描述将大项目分解为子项目.
将每个作品设置在其自己的仓库;


git submodule

Break your big project to sub projects as you did described it.
Set each piece in its own repo;

现在使用以下命令将每个子项目添加到您的主项目中:

Now add each sub project to you main project using :

git submodule add <url>

一旦将项目添加到您的仓库中,就必须进行初始化和更新.

Once the projected is added tot your repo you have to init and update it.

git submodule init
git submodule update

Git 1.8.2 开始,添加了新选项--remote

As of Git 1.8.2 new option --remote was added

git submodule update --remote --merge

fetch 从每个子模块, merge them in check out 子模块的最新版本.

will fetch the latest changes from upstream in each submodule, merge them in, and check out the latest revision of the submodule.

文档所述:

--remote

此选项仅对更新命令有效.不用使用超级项目记录的SHA-1更新子模块,而要使用子模块的远程跟踪分支的状态.

This option is only valid for the update command. Instead of using the superproject’s recorded SHA-1 to update the submodule, use the status of the submodule’s remote-tracking branch.

这等效于在每个子模块中运行git pull.

This is equivalent to running git pull in each submodule.

但是,在C语言中的bug修复情况下,如果影响与父层共享的代码,我该如何推送提交?

同样:使用子模块会将代码放置在主项目中,作为其内容的一部分.将其本地放置在文件夹中或将其作为子模块的一部分的区别在于,在子模块中,内容被管理(提交)到另一个独立的存储库中.

Again: using submodule will place your code inside your main project as part of its content. The difference between having it locally inside the folder or having it as part of a submodule is that in submodule the content is managed (commited) to a different standalone repository.

这是子模块的说明-另一个项目中的项目,其中每个项目都是独立项目.

This is an illustration of submodule - project inside another project in which each project is a standalone project.

Git子树允许您将任何存储库作为另一个存储库的子目录插入

submodule非常相似,但主要区别在于代码的管理位置.在子模块中,内容放置在单独的存储库中,并在此处进行管理,使您也可以将其克隆到许多其他存储库中.

Very similar to submodule but the main difference is where your code is managed. In submodules the content is placed inside a separate repo and is managed there which allow you to clone it to many other repos as well.

subtree 将内容作为根项目的一部分而不是单独的项目进行管理.

subtree is managing the content as part of the root project and not in a separate project.

您无需阅读如何设置和了解如何使用它的方法,而只需阅读这篇出色的文章,便会对其进行全面解释.

Instead of writing down how to set it up and to understand how to use it you can simply read this excellent post which will explain it all.

https://developer.atlassian. com/blog/2015/05/the-power-of-git-subtree/

这篇关于如何在项目中使用2个GIT回购? (git子模块,子树)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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