Git子模块分离头状态 [英] Git submodule detached head state
问题描述
我已经在外部/subA和外部/subB中为项目SubA和subB添加了2个子模块.
I've added 2 submodules to a project, subA and subB, in externals/subA and externals/subB.
今天,另一位团队成员提交了他的代码,当将其拉出时,在externals/subA和externals/subB中使用git status
时,subA和subB都显示分离的头部状态.
Today another team member committed his code and when it is pulled, both subA and subB show detached head status when using git status
within externals/subA and externals/subB.
我首先做了git submodule update
,并且没有报告任何错误.我再次尝试了git submodule init
和git submodule update
,但是它没有改变.
I did git submodule update
first and that reported no errors. I tried then git submodule init
and git submodule update
again but it did not change.
如何使子模块恢复同步?是什么导致子模块出现这种情况?自从我们开始以来,这是第一次出现问题.谢谢.
How can we get the submodules back to be in sync? What causes this for the submodules? This is first time problem has arised since we began. Thanks.
推荐答案
在定义的 中已将一个子模块签入到分离的HEAD中:它表示记录为 父回购索引中的"https://stackoverflow.com/a/2227598/6309">gitlink .
A submodule is by definition checked out in detached HEAD: it represents a specific SHA1 recorded as a gitlink in the parent repo index.
请参见" git submodule update
"为了确保子模块正在跟踪分支:
See "git submodule update
" in order to make sure a submodule is tracking a branch:
# add submodule to track master branch
git submodule add -b master [URL to Git repo];
# update your submodule
git submodule update --remote
# or (with rebase)
git submodule update --rebase --remote
注意:如此处显示的 所示,即使已配置了子模块,任何git submodule update
命令都将自动分离HEAD.跟随分支.
Note: as shown here, any git submodule update
command would automatically detach the HEAD, even if the submodule is configured to follow a branch.
作为测试添加 git config submodule.<name>.update
合并,因为默认情况下,更新会签出提交(分离的HEAD)
As test add git config submodule.<name>.update
merge, because by default, an update checks out the commit (detached HEAD)
user859375 添加
当运行命令" The git submodule is detached in the init stage itself when running command " 我了解git引用并检出了gitsubmodules的特定提交. I understand git refers and check-out particular commit of gitsubmodules. 因此,我们创建了一个脚本来运行" So, we created a script to run " 这样,当我们在本地计算机上设置存储库时,我们就可以保持连接的磁头状态. This way we're able to keep the attached head state when setting up repo in local machine. 这篇关于Git子模块分离头状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!git submodule update --init --recursive
"时,git子模块会在init阶段本身分离.
git submodule update --init --recursive
".git submodule foreach git checkout master
"和"git submodule foreach git pull origin master
" git submodule foreach git checkout master
" and "git submodule foreach git pull origin master
" among other things.
是的,我们运行"git submodule update --remote --merge
"当我们需要更新子模块以反映远程更改时.
And yes we run "git submodule update --remote --merge
" when we need to update submodules to reflect changes in remote.