../extern/Lib1 是指 Git 存储库吗?
如果没有,Git 将不知道如何将 Git 存储库 url 指向其 .gitmodule
另外,请尝试:
- 目的地
lib不已经存在(甚至是空的)
- 使用绝对路径而不是相对路径(您可以使用相对路径,但以防万一,这里值得一试)
关于子模块的一些很好的来源是:
由于这里只有绝对路径有效,这意味着相对路径需要一个引用来进行比较。
该引用是应该在您的DirName/NewRepo_withSubmodules/.git/config 文件中的“远程来源”,如下所示:
$ cat .git/config
...
[remote "origin"]
url = /path/to/DirName/NewRepo_withSubmodules/.git
fetch = +refs/heads/*:refs/remotes/origin/*
...
如果您在 ../DirName/NewRepo_withSubmodules/.git/config 文件中确实有该部分,您应该能够使用相对路径将 ../Extern/Lib1 添加为子模块。
以上所有内容的灵感来自 git 子模块手册页的以下部分:
<repository> 是新子模块源存储库的 URL。
这可能是一个绝对 URL,或者(如果它以 ./ 或 ../ 开头),相对于超级项目的 origin 存储库的位置。。 p>
因此,如果NewRepo_withSubmodules 是刚刚创建的本地 Git 存储库(当然没有“起源”),则应该定义一个人为的“远程起源”(即使起源指向自身),如果仅允许使用其他子模块存储库的相对 url。
Git 2.13(2017 年第二季度)将改进对子模块默认来源的检测。
参见Stefan Beller (stefanbeller)commit d1b3b81(2017 年 2 月 25 日)。
(由 Junio C Hamano -- gitster -- 合并于 commit ae900eb,2017 年 3 月 10 日)
submodule init: 警告回退到本地路径
作为now documented:
<repository> 是新子模块源存储库的 URL。
这可能是一个绝对 URL,或者(如果它以 ./ 或 ../ 开头)相对于超级项目的默认远程存储库的位置
(请注意,要指定位于超级项目“bar.git”旁边的存储库“foo.git”,您必须使用“../foo.git”而不是“./foo.git”——正如人们所期望的那样遵循相对 URL 的规则时 - 因为 Git 中相对 URL 的评估与相对目录的评估相同。
默认远程是当前分支的远程跟踪分支的远程。
如果不存在这样的远程跟踪分支或HEAD 已分离,则假定“origin”为默认远程。
如果超级项目没有配置默认远程,则超级项目是它自己的权威上游和当前。
而是使用工作目录。
Git 2.20(2018 年第四季度)改进了对子模块的本地路径支持。
参见Stefan Beller (stefanbeller)commit e0a862f(2018 年 10 月 16 日)。
(由 Junio C Hamano -- gitster -- 合并于 commit 3fc8522,2018 年 11 月 6 日)
submodule helper:如果需要,将相对 URL 转换为绝对 URL
“git submodule update”调用的子模块助手update_clone,
如果需要,克隆子模块。
由于子模块使用 URL 指示它们是否处于活动状态,因此解析相对 URL 的步骤在“submodule init”步骤中完成。如今,子模块可以在不调用显式 init 的情况下配置为活动的,例如通过配置submodule.active。
当尝试获取以这种方式设置为活动的子模块时,我们将
回退到在 .gitmodules 中找到的 URL,它可能与
超级项目,但我们还没有解决它:
git clone https://gerrit.googlesource.com/gerrit
cd gerrit && grep url .gitmodules
url = ../plugins/codemirror-editor
...
git config submodule.active .
git submodule update
fatal: repository '../plugins/codemirror-editor' does not exist
fatal: clone of '../plugins/codemirror-editor' into submodule path '/tmp/gerrit/plugins/codemirror-editor' failed
Failed to clone 'plugins/codemirror-editor'. Retry scheduled
[...]
fatal: clone of '../plugins/codemirror-editor' into submodule path '/tmp/gerrit/plugins/codemirror-editor' failed
Failed to clone 'plugins/codemirror-editor' a second time, aborting
[...]
要解决此问题,请考虑解决相关问题的函数
“git submodule init”中的 URL(在 init_submodule 函数的子模块助手中)并在 update_clone 助手中的适当位置调用它。