git子模块分支会随主项目的分支切换吗? [英] Does git submodule branch switch along with main project's branch?
问题描述
当我切换主项目的分支,这是否也切换子模块的分支?如何处理这种情况的git?
我最近遇到类似的问题。 (我会让你读这个答案的内容,因为它给你我的答案的背景)。
子模块只是对回购和提交的引用在这个回购中。
当您切换分支时,引用可能会改变(如果您切换到的分支使用不同的引用),但子模块的文件系统将保持不变。
因此,编写 git status
会产生一个结果,表明您的子模块状态不同于当前 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屋!