git:子模块跟踪当前分支

问题描述 投票:1回答:2

根据git documentation,我应该能够运行这个命令:

git submodule add -b . https://my/repo

并添加了一个子模块,它将跟踪超级项目当前分支的头部。

存储库的分支添加为子模块。分支的名称在.gitmodules中记录为submodule..branch for update --remote。一个特殊的价值。用于指示子模块中分支的名称应与当前存储库中的当前分支的名称相同。

但是,当我这样做时,我收到此错误:

致命的:'起源/。'不是提交和分支'。'无法从中创建

我正在运行git 2.21。我完全错误地阅读了说明吗?

git git-submodules
2个回答
1
投票

git submodule add似乎没有任何代码可以检查点。克隆之后,它会尝试检查分支“。”,这自然不存在。

但是,git submodule update --remote确实有一张支票,并使用“。”特别。

要使其工作,您需要:

  1. git submodule add -b master https://my/repo
  2. 编辑.gitmodules文件并将分支从master更改为点“。”
  3. git submodule update --remote
  4. 利润

每次在超级项目上运行更新时,它都会获得分支的提示。

无论文档是否不清楚,或者添加子模块存在错误,我都不确定。


0
投票

选项-b需要存储库https://my/repo中的分支名称。例如,master

git submodule add -b master https://my/repo

Git无法“跟踪超级项目当前分支的负责人”。必须明确给出分支。

当您使用git checkout切换超级项目的分支时,git不会自动切换子模块的分支 - 您必须手动或从git submodule update钩子运行post-checkout

Why is git submodule update not automatic on git checkout?

https://stackoverflow.com/search?q=%5Bgit-submodules%5D+switch+branch

© www.soinside.com 2019 - 2024. All rights reserved.