git子模块始终是分离的,即使在跟踪分支时也是如此 [英] git submodule is always detached, even when tracking branch

查看:156
本文介绍了git子模块始终是分离的,即使在跟踪分支时也是如此的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个配置为跟踪特定分支的git子模块:

I have a git submodule configured to track a specific branch:

[submodule "subproject"]
path = subproject
url = ../subproject.git
branch = v2.44

在我的构建脚本中,我希望能够查询子项目的分支,因此我使用cd subproject && git rev-parse --abbrev-ref HEAD.我希望它能输出v2.44,但它总是输出HEAD.

In my build script, I want to be able to query the branch of the subproject, so I use cd subproject && git rev-parse --abbrev-ref HEAD. I would expect this to output v2.44, but it always outputs HEAD.

当我进入subproject/并检查分支时,我得到:

When I go into subproject/ and inspect the branch, I get:

git branch -v
* (HEAD detached at b69ac07) b69ac07 Another commit
  master                     36096e7 Some commit

这是怎么回事?为什么我会被分离,而不是放在v2.44分支上?

What's going on here? Why would I be detached rather than on the v2.44 branch?

如果我手动git checkout v2.44,与我进行git checkout v2.43相比,父级git repo也不会检测到对该子模块的任何形式的修改,然后它确实注意到该子模块已被修改.

If I manually git checkout v2.44, the parent git repo doesn't detect any sort of modification to the submodule either, versus if I were to git checkout v2.43 and then it does notice that the submodule was modified.

推荐答案

这很正常!

子模块声明中的 branch 表示法仅在通过git submodule update --rebasegit submodule update --merge或其他一些特殊的怪异情况通过更新子模块时使用.在所有其他时间,每个子模块都有一个分离的HEAD,在由使用子模块的超级项目中的 gitlink索引条目选择的提交时分离.

The branch notation in a submodule declaration is used only when updating the submodule, via git submodule update --rebase or git submodule update --merge, or a few other special oddball cases. At all other times, each submodule has a detached HEAD, detached at the commit selected by the gitlink index entry in the superproject that is using the submodule.

(也就是说,在 superproject 中,某些提交 C 已签出.Commit C 说:当您使用子模块时S,它应该在提交CS上.这东西叫做 gitlink ,它从提交 C 复制到索引,然后git submodule update进入子模块,并以分离的HEAD的形式签出该特定的提交.)

(That is, in the superproject, some commit C is checked out. Commit C says: When you use submodule S, it should be on commit CS. This thing is called a gitlink and it gets copied from commit C to the index, and then git submodule update goes into the submodule and checks out that particular commit, as a detached HEAD.)

这篇关于git子模块始终是分离的,即使在跟踪分支时也是如此的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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