git/子模块:更新后提前分离--rebase

问题描述 投票:0回答:0

根据文档

man git submodule update
,如果使用选项
--rebase
运行,那么它永远不应该使子模块的HEAD处于分离状态。

--rebase
           This option is only valid for the update command. Rebase the current branch onto the commit recorded in the superproject. If this option is given, the
           submodule’s HEAD will not be detached. If a merge failure prevents this process, you will have to resolve these failures with git-rebase(1). If the key
           submodule.$name.update is set to rebase, this option is implicit.

但是,在下面的基本示例中,它似乎没有按预期工作

$ pwd
/home/user/my_repo

$ cat .gitmodules 
[submodule "my_submodule"]
    path = my_submodule
    url = [email protected]:user/my_submodule.git
    branch = main

$ # This is a fresh clone, ensure that HEAD is detached
$ # This is an expected behavior so far

$ (cd my_submodule/ && git branch)
* (HEAD detached at f1129ce)
  main

$ # Let's update submodules with --rebase command
$ # The expected behavior is that HEAD will not
$ # be detached, but rather pointing to main

$ git submodule update --remote --init --rebase

$ # Nope :-( HEAD is still detached
$ (cd my_submodule/ && git branch)
* (HEAD detached at f1129ce)
  main

$ rpm -qf `which git`
git-core-2.39.1-1.fc37.x86_64
$ git --version
git version 2.39.1

我对文件的解释是否错误?有人可以帮我澄清一下吗?

git git-submodules rebase git-detached-head
© www.soinside.com 2019 - 2024. All rights reserved.