你是对的。用户 mkungla 从为什么我的 GIT 子模块 HEAD 与主模块分离?是胡说八道。
添加一个branch
选项.gitmodule
根本与子模块的分离行为无关。
从git submodule --help
,HEAD 分离是 的默认git submodule update --remote
行为。
首先,不需要指定要跟踪的分支。origin/master
是要跟踪的默认分支。
- 偏僻的
不要使用超级项目记录的 SHA-1 来更新子模块,而是使用子模块的远程跟踪分支的状态。使用的遥控器是分支的遥控器 ( branch.<name>.remote
),默认为origin
. 使用的远程分支默认为master
.
为什么
那么为什么 HEAD 之后分离update
呢?因为默认行为submodule.$name.update
是checkout
.
- 查看
签出子模块中分离的 HEAD上记录在超级项目中的提交。这是默认行为,此选项的主要用途是submodule.$name.update
在设置为 以外的值时覆盖checkout
。
如何
如果您希望子模块自动与远程分支合并,请使用--merge
或--rebase
。
- 合并
此选项仅对更新命令有效。将超级项目中记录的提交合并到子模块的当前分支中。如果给出这个选项,子模块的 HEAD 将不会被分离。
--rebase
将当前分支重新定位到超级项目中记录的提交。如果给出这个选项,子模块的 HEAD 将不会被分离。
你需要做的就是,
git submodule update --remote --merge
# or
git submodule update --remote --rebase
通过设置为或,还可以选择将--merge
或--rebase
作为默认行为。git submodule update
submodule.$name.update
merge
rebase
这是一个关于如何在.gitmodule
.
[submodule "bash/plugins/dircolors-solarized"]
path = bash/plugins/dircolors-solarized
url = https://github.com/seebi/dircolors-solarized.git
update = merge # <-- this is what you need to add
我的整个答案是基于手册。git submodule --help
.