使用GIT更新子模块时出现致命错误

Dev*_*xon 37 git ssh github git-submodules

我正在尝试更新这个git repositary的子模块但是我一直遇到致命的错误:

[root@iptlock ProdigyView]# git submodule update --recursive
Cloning into core...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Clone of 'git@github.com:ProdigyView/ProdigyView-Core.git' into submodule path 'core' failed
Run Code Online (Sandbox Code Playgroud)

或者这样

[root@iptlock root]# git clone --recursive https://github.com/ProdigyView/ProdigyView.git
Cloning into ProdigyView...
remote: Counting objects: 438, done.
remote: Compressing objects: 100% (275/275), done.
remote: Total 438 (delta 172), reused 394 (delta 128)
Receiving objects: 100% (438/438), 8.03 MiB | 5.19 MiB/s, done.
Resolving deltas: 100% (172/172), done.
Submodule 'core' (git@github.com:ProdigyView/ProdigyView-Core.git) registered for path 'core'
Cloning into core...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Clone of 'git@github.com:ProdigyView/ProdigyView-Core.git' into submodule path 'core' failed
Run Code Online (Sandbox Code Playgroud)

有关为什么会发生子模块的任何想法?回购是这个:

https://github.com/ProdigyView/ProdigyView

(如果我不尝试将子模块克隆为子模块,则可以克隆子模块.)

Dan*_*ton 73

问题是git无法找到从服务器下载repo所需的公钥,解决方案是使用公共URL.

在.gitmodule文件中,您将找到以下条目:

[submodule "example"]
    path = example
    url = git@github.com:webhat/example.git
Run Code Online (Sandbox Code Playgroud)

需要将URL更改为模块的公共URL:

[submodule "example"]
    path = example
    url = https://github.com/webhat/example.git
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,前缀git @已更改为https://并且infix :变为/

编辑: 在您自己的存储库中,您可能需要使用git://而不是https://

之前的答案对我来说不清楚,所以我补充说.

编辑2: 如果您发现需要运行git submodule sync或需要编辑.git/config才能使其工作,您可能已经为子模块设置了遥控器.

  • 这对我有用,但在运行`git submodule update --init --recursive之前必须运行``git submodule sync` (13认同)
  • 重复.git/config中的过程 (3认同)
  • 我今天遇到了同样的问题,Github似乎只通过HTTPS提供公共克隆.您的示例中的URL将是"https:// github.com/webhat/example.git" (2认同)

小智 37

如果它可以帮助一些人:

我更新了我的.gitmodules

[submodule "example"]
  path = example
  url = https://github.com/webhat/example.git
Run Code Online (Sandbox Code Playgroud)

然后我也更新我的.git/config

[submodule "example"]
  url = https://github.com/webhat/example.git
Run Code Online (Sandbox Code Playgroud)

就像你们之前说的那样(我感谢你).

然后我更新我的.git/modules/example/config

[remote "origin"]
  fetch = [...]
  url = https://github.com/webhat/example.git
Run Code Online (Sandbox Code Playgroud)

并完成我做

git submodule sync
git submodule init
git submodule update
Run Code Online (Sandbox Code Playgroud)


RC_*_*_02 6

您可以在 jenkins 作业的 Build --> "Execute shell" 部分手动传入密钥:

ssh-agent bash -c 'ssh-add {path_to_private_key}; git submodule update --init --recursive'

例子:

ssh-agent bash -c 'ssh-add /var/lib/jenkins/.ssh/jenkins_rsa; git submodule update --init --recursive'


hme*_*ia1 6

对于我来说,这种情况发生过很多次,我在 .bash_profile 中放置了一个函数(适用于 BSD sed / GNU / Mac):

\n\n
gitfix () {\nif [ -f "./.gitmodules" ] ; then\n    sed -E -i.bak -e "s/(url *= *)(.*:)(.*)/\\1https:\\/\\/github.com\\/\\3/g" .gitmodules \\\n    git submodule sync\n    git submodule update --init --recursive\nfi\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

一班轮:

\n\n
sed -E -i.bak -e "s/(url *= *)(.*:)(.*)/\\1https:\\/\\/github.com\\/\\3/g" .gitmodules ; git submodule sync ; git submodule update --init --recursive\n
Run Code Online (Sandbox Code Playgroud)\n\n

vim 搜索/替换:

\n\n
%s/\\(url\\s*=\\s*\\)\\(.*:\\)\\(.*\\)/\\1https:\\/\\/github.com\\/\\3/\n
Run Code Online (Sandbox Code Playgroud)\n\n

基于 Dani\xc3\xabl \ 的答案的底层解决方案

\n


小智 5

以下步骤将解决该问题。

  1. 删除本地子模块的文件夹。
  2. git submodule sync
  3. 然后 git submodule update --init

希望这可以帮助。


Dev*_*xon -10

弄清楚了。.gitmodule 文件中的路径无法下载子模块。

  • 我也有同样的问题。您能否详细说明一下出了什么问题以及如何修复它? (7认同)
  • 修改两个地方的路径后,我不断收到相同的错误。我必须删除子模块的文件夹。执行 `git submodulesync` 然后执行 `git submodule update --init` (5认同)
  • 这个答案非常不清楚。Khune Vu 的建议也没有解决问题。 (3认同)