git子模块分支会随主项目的分支切换吗? [英] Does git submodule branch switch along with main project's branch?

查看:3385
本文介绍了git子模块分支会随主项目的分支切换吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我开始了解git子模块。他们似乎是自己的项目与他们自己的git结构和分支。

当我切换主项目的分支,这是否也切换子模块的分支?如何处理这种情况的git?

解决方案

我最近遇到类似的问题。 (我会让你读这个答案的内容,因为它给你我的答案的背景)。

子模块只是对回购和提交的引用在这个回购中。

当您切换分支时,引用可能会改变(如果您切换到的分支使用不同的引用),但子模块的文件系统将保持不变。

因此,编写 git status 会产生一个结果,表明您的子模块状态不同于当前 HEAD 中的模块状态。 为了使子模块指向 HEAD 的右侧提交,只需调用:

  $ git子模块更新

另外,你的子模块的分支对封装的回购并不感兴趣,因为引用总是添加到提交而不是分支。因此,子模块中的分支将仅反映子模块的分支策略,并且不需要匹配封装的存储库的分支策略。

Recently I got to know git submodules. They appear to be self-sufficient projects with their own git structure and branches.

When I switch main project's branch, does this also switch submodule's branch? How does git handle this situation?

解决方案

I recently came across a similar question. (I'll let you read the content of this answer as it gives you the background to my answer).

A submodule is just a reference to a repo and a commit in this repo.
When you switch branch, the reference may change (if the branch you're switching to uses a different reference) but the filesystem of the submobule will remain untouched.
So writing git status will yield a result showing that your submodule status differs from the one in your current HEAD.

To make the submodule point to the right commit for HEAD, simply invoke:

$ git submodule update 

In addition, the branch of your submodule is not interesting to the enclosing repo as the reference is always added toward a commit and not toward a branch. The branches in your submodule will therefore only reflect your branching strategy for the submodule and do not need to match the enclosing repository's branching strategy.

这篇关于git子模块分支会随主项目的分支切换吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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