如何将文件夹从git仓库链接到另一个仓库? [英] How to link folder from a git repo to another repo?

查看:890
本文介绍了如何将文件夹从git仓库链接到另一个仓库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个公共存储库来放置主存储库(私有)中的一些示例文件.有什么方法可以将几个文件夹从git repo软链接到另一个git repo?

I want to create a public repo to put some sample files from my main repo (private). Is there any way to soft link few folders from a git repo to another git repo?

推荐答案

然后,您应该使用子模块来完成此任务.

Then you should use submodules for this task.

子模块是同一根目录下的不同git存储库.
这样,您可以在根存储库中的文件夹级别管理2个不同的项目

Submodule are different git repositories under the same root.
This way you can manage 2 different project at folder level inside the root repository

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 so far.
Now add each sub project to you main project using :

git submodule add <url>

将项目添加到您的存储库后,您必须进行初始化和更新.

Once the project is added to 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/

这篇关于如何将文件夹从git仓库链接到另一个仓库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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