在另一个git repo内维护一个Git repo [英] Maintaining a Git repo inside another git repo

查看:73
本文介绍了在另一个git repo内维护一个Git repo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git repo,其中包含AngularJS网络应用程序.

I have a git repo which contains an AngularJS web app.

它具有一个名为build的子文件夹,该子文件夹由gulp任务创建.我正在部署到Azure,因此它直接连接到我的bitbucket目录.

It has a subfolder called build, which gets created by a gulp task. I am deploying to Azure, so it is connected directly to my bitbucket directory.

我想将构建文件夹作为从其部署Azure应用程序的单独的git仓库.如何在git中实现这一目标?

I want to make build folder as a separate git repo from which the Azure app is being deployed. How do I achieve this in git??

推荐答案

您有以下几种选择:

  • 子模块
  • 子树

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 into 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

将从每个子模块 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 repo内维护一个Git repo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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