Does git submodule branch switch along with main project's branch?

谁说我不能喝 提交于 2019-12-24 02:05:33

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/40219209/does-git-submodule-branch-switch-along-with-main-projects-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!