我有一个 git 存储库
repoA
,它是父存储库。其中,我有一个子模块 repoB
存储在克隆的 repoB
目录中的目录 repoA
中。
几年前,当我第一次开始这个项目时,我一直在
devDir
克隆到的目录repoA
中进行操作。直到今天,我可以在devDir
内很好地推送/获取。
最近,我想将
repoA
的另一个版本克隆到demoDir
中。将 repoA
克隆到 demoDir
效果很好,我可以看到所有正确的文件。太棒了!
现在,当我执行
git submodule update --init
时,我会收到以下错误消息:
user@devBox:~/repos/demoDir> git submodule update --init
Cloning into '/home/user/repos/demoDir/repoB'...
remote:
remote: ========================================================================
remote:
remote: ERROR: The namespace you were looking for could not be found.
remote:
remote: ========================================================================
remote:
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of '[email protected]:groupname/repoA.git/repoB' into submodule path '/home/user/repos/demoDir/repoB' failed
当我
cat demoDir/.gitmodules
我明白了
[submodule "repoB"]
path = repoB
url = ./repoB/
这很好。
然后,当我
cat demoDir/.git/config
我明白了
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = [email protected]:groupname/repoA.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[submodule "repoB"]
active = true
url = [email protected]:groupname/repoA.git/repoB
现在最后一个 url 行让我感到担忧,因为这不是克隆
repoB
的正确路径(当我进入 gitlab 的网站并单击克隆按钮时,它给我的 url 是 [email protected]:groupname/repoB.git
)。
当我编辑
demoDir/.git/config
并将最后一行更改为 url = [email protected]:groupname/repoB.git
时,我可以运行 git submodule update --init
并且它能够很好地检查所有内容。
这里真正的亮点是,当我
cat devDir/.git/config
时,我得到的输出(对于子模块)基本上与demoDir
完全相同,只是它被翻转了
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = [email protected]:groupname/repoA.git
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = [email protected]:groupname/repoA.git
[branch "master"]
remote = origin
merge = refs/heads/master
[submodule "repoB"]
url = [email protected]:groupname/repoA.git/repoB
active = true
[... a bunch of branches that I don't think matter]
那么到底怎么一个克隆可以正常工作,而另一个却不能呢?
我尝试过运行
git submodule sync
但没有骰子。
我排除的事情:
repoA
就可以了。demoDir/.gitmodules
和 demoDir/.git/config
中所述的路径实际上存在于 gitlab 站点的浏览器中。感谢任何和所有帮助!
你写:
当我 cat demoDir/.gitmodules 时我看到了
[submodule "repoB"] path = repoB url = ./repoB/
这很好。
这就是您所看到的行为的原因。
url
应该是 ../repoB
。这在git submodule add
文档中提到过:
(请注意,要指定位于超级项目 bar.git 旁边的存储库 foo.git,您必须使用
而不是../foo.git
- 正如人们在遵循相对 URL 的规则 - 因为 Git 中相对 URL 的评估与相对目录的评估相同)。./foo.git
请注意,在您的情况下
.git
不是必需的,因为它是由 GitLab 自动添加的。
然后你写:
这里真正的亮点是当我
我得到基本上完全相同的输出(对于子模块) 那么,究竟如何一个克隆可以正常工作,而另一个却不能呢?cat devDir/.git/config
您必须检查子模块的配置文件以检查
remote.origin.url
的配置内容。也就是说,如果你跑步
cd devDir/repoB
git config --get remote.origin.url
我认为你会得到
[email protected]:groupname/repoB.git
,这可以解释它为什么有效。一旦子模块初始化,Git 仅使用此值,而不是超级项目中的submodule.repoB.url
。