克隆到同一个目录中的多个git存储库 [英] multiple git repositories cloned into the same directory
问题描述
我的项目有一个标准存储库
/home/repo/.git
code>
这是我克隆的存储库以获取新网站的基本代码
ie ie克隆它到
/ var / www / site1
我也有几个模块作为存储库创建,有些网站将使用这些模块,有些则不会。
/home/modules/mod1/.git
/home/modules/mod2/.git
有没有一种方法可以将这些模块克隆到同一个站点文件夹中?
/ var / www / site1
模块目录设置为与主仓库相同的文件夹结构,当我将它们克隆在主仓库克隆顶部时,它们应合并/替换现有文件。 (很少有任何文件重叠)
我的最佳解决方案是以某种方式命名回购站点,以便在部署新站点时执行类似以下操作:
cd / var / www / newsite
git clone /home/repo/.git
git clone / home / modules / mod1 / .git
git clone /home/moudles/mod2/.git
和when
git pull origin master
git pull mod1
git pull mod2
或最好:
git pull origin master
也会调用拉 mod1
和 mod2
。
我已经一直在寻找git子模块和分支,但无法弄清楚它们是否是我需要的。 解决方案
到你想要的部署命令:
cd / var / www /
git clone /home/repo/.git newsite
git remote add mod1 /home/modules/mod1/.git
git remote add mod2 /home/moudles/mod2/.git
cd newsite
git merge mod1 / master
git merge mod2 / master
解释:
正如你所说的,你的主模块(/ home / repo)和你的 mod1
, mod2
等具有相同的文件夹结构。因此子模块不适合使用,因为子模块必须位于主回购库的子目录中。在这个版本中,你的本地git仓库(由 clone
创建)知道三个远程仓库。在合并
操作之后,其状态将不会与它们中的任何一个相同。 mod1的 merge
将引入任何由mod1拥有的新文件。如果 home / repo
中的任何文件与 mod1
等名称相同,则可能会发生合并冲突。可以提供一个< mod1
总是选择版本,我相信你说的是你想要的行为。
I've got a standard repository for my project
/home/repo/.git
this is the repository i clone to get the base code for new websites i.e. i cloned this to
/var/www/site1
i also have several modules that i've created as repositories, some websites will be using these modules and some will not.
/home/modules/mod1/.git
/home/modules/mod2/.git
is there a way that i can clone those modules into the same site folder?
/var/www/site1
the module directories are set up with the same folder structure as the master repo, when i clone them on top of the master repo clone they should merge/replace existing files. (rarely any file overlap)
my optimal solution would be naming the repo's in some way so that when i deploy a new site I do something like:
cd /var/www/newsite
git clone /home/repo/.git
git clone /home/modules/mod1/.git
git clone /home/moudles/mod2/.git
and when I have updates to make to the site I could do a pull like:
git pull origin master
git pull mod1
git pull mod2
or preferably:
git pull origin master
would also call the pulls on mod1
and mod2
.
I've been looking at git submodules and branches but can't figure out if they are what I need.
Here's a suggested slight change to your desired deploy commands:
cd /var/www/
git clone /home/repo/.git newsite
git remote add mod1 /home/modules/mod1/.git
git remote add mod2 /home/moudles/mod2/.git
cd newsite
git merge mod1/master
git merge mod2/master
Explanation:
As you said, your main module (/home/repo) and your mod1
, mod2
etc. have the same folder structure. Submodules then aren't really appropriate since a submodule has to live in a subdirectory of your main repo. In this version, your local git repository (created by the clone
) knows about three remote repositories. After the merge
operations, its state won't be the same as any of them. The merge
of mod1 will bring in any new files "owned" by mod1. You may get merge conflicts if any files in home/repo
have the same name as those in mod1
, etc. You could supply a flag to merge
to select the version from mod1
always, which I believe you said is the behavior you want.
这篇关于克隆到同一个目录中的多个git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!