Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将1个git存储库链接到其他存储库?_Git_Repository - Fatal编程技术网

如何将1个git存储库链接到其他存储库?

如何将1个git存储库链接到其他存储库?,git,repository,Git,Repository,如何将1个git存储库链接到其他存储库 假设我有以下存储库: /var/Common.git /var/Project1.git /var/Project2.git 现在,我想在其他存储库中使用Common.git。我该怎么做?这是设计git子模块的完美案例: 在Project1和Project2中,您添加了公共的子模块。然后您将git子模块签出 在克隆的repo中,它只存储公共git的散列。因此,您可以git子模块init和checkout。您可能正在寻找: 子模块允许将外部存储库嵌入到源代码

如何将1个git存储库链接到其他存储库

假设我有以下存储库:

/var/Common.git

/var/Project1.git

/var/Project2.git


现在,我想在其他存储库中使用Common.git。我该怎么做?

这是设计git子模块的完美案例:

在Project1和Project2中,您添加了公共的子模块。然后您将
git子模块签出


在克隆的repo中,它只存储公共git的散列。因此,您可以
git子模块init
和checkout。

您可能正在寻找:

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

有一个关键词是嵌入的:Common.git的实际克隆将嵌入到其他每个项目中。这通常适用于不打算在其他项目中修改它的情况,只需使用一个版本,然后不时地从原始的Common.git更新该版本。你可以这样做:

# add Common.git as a submodule at the path "common" inside this repo
git submodule add /var/Common.git common
# initialize it, clone, and check out a copy
git submodule update --init
# commit the addition of the submodule
git commit
请注意,子模块的路径将提交到您的存储库中,因此您应该使用公开可用的URL。如果要在本地对其进行自定义,可以运行
git submodule init
,在.git/config中编辑url,然后运行
git submodule update
。如果您还有其他问题,请查阅手册或搜索SO;这里有很多子模块问题

另一方面,如果要在每个项目中编辑Common.git的内容,可能需要使用它,它是git子树合并功能的友好包装器。这将使您可以将common.git的内容视为每个项目中的跟踪内容,同时仍然能够拆分对它的提交并将其合并到common.git本身,并将对common.git的更新合并回项目中