git:子模块跟踪当前分支

时间:2019-03-06 20:56:13

标签: git git-submodules

根据this,我应该能够运行以下命令:

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

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

  

要添加为子模块的存储库分支。分支的名称记录为.gitmodules中的submodule..branch以进行更新--remote。的特殊值。用来表示子模块中的分支名称应与当前存储库中的当前分支相同。

但是,当我这样做时,会出现此错误:

  

致命:“来源/”。不是提交,而是分支“。”无法从中创建

我正在运行git 2.21。我看错了指示吗?

2 个答案:

答案 0 :(得分: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. 利润

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

我不确定文档是否清晰,或者添加子模块时存在错误。

答案 1 :(得分:0)

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

git checkout

Git不能“跟踪超级项目当前分支的头部”。必须明确指定分支。

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

请参见Why is git submodule update not automatic on git checkout?

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

相关问题