[英]Fatal Error when updating submodule using GIT
我正在尝试更新此 git 存储库的子模块,但我不断收到致命错误:
[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
或者这样
[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
关于子模块为什么会发生这种情况的任何想法? 回购是这个:
https://github.com/ProdigyView/ProdigyView
(如果我不尝试将其克隆为子模块,则可以克隆该子模块。)
问题是 git 找不到从您的服务器下载 repo 所需的公钥,解决方案是使用公共 url。
在文件 .gitmodule 中,您将找到以下条目:
[submodule "example"]
path = example
url = git@github.com:webhat/example.git
URL 需要更改为模块的公共 URL:
[submodule "example"]
path = example
url = https://github.com/webhat/example.git
如您所见,前缀git@已更改为https://并且中缀:变为/
编辑:在您自己的存储库中,您可能需要使用git://
而不是https://
之前的答案对我来说不清楚,所以我添加了这个。
编辑 2:如果您发现需要运行git submodule sync
或需要编辑.git/config
以使其工作,您可能已经为子模块设置了远程。
如果它可以帮助某些人:
我更新了我的 .gitmodules
[submodule "example"]
path = example
url = https://github.com/webhat/example.git
然后我也更新我的 .git/config
[submodule "example"]
url = https://github.com/webhat/example.git
就像你们中的一些人之前说过的那样(我感谢你们)。
然后我更新我的 .git/modules/example/config
[remote "origin"]
fetch = [...]
url = https://github.com/webhat/example.git
为了完成我做
git submodule sync
git submodule init
git submodule update
您可以在 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'
以下步骤将解决该问题。
git submodule sync
git submodule update --init
希望这可以帮助。
这对我来说发生了很多次,我在我的 .bash_profile 中放置了一个函数(适用于 BSD sed / GNU / Mac):
gitfix () {
if [ -f "./.gitmodules" ] ; then
sed -E -i.bak -e "s/(url *= *)(.*:)(.*)/\1https:\/\/github.com\/\3/g" .gitmodules \
git submodule sync
git submodule update --init --recursive
fi
}
一个班轮:
sed -E -i.bak -e "s/(url *= *)(.*:)(.*)/\1https:\/\/github.com\/\3/g" .gitmodules ; git submodule sync ; git submodule update --init --recursive
vim 搜索/替换:
%s/\(url\s*=\s*\)\(.*:\)\(.*\)/\1https:\/\/github.com\/\3/
基于 Daniël 答案的基础解决方案
我有同样的问题。 但是,在我的情况下,团队希望使用来自 .gitmodules 的 SSH 访问,因此修改 URL 以使用 http:// 不是一个选项。
最终,我的问题是 ~/.ssh/config 文件不正确。 配置文件有一些错误的设置,所以每次我真的想访问 git@github.com 时,我实际上都试图访问错误的服务器。 我通过执行以下命令发现了这一点:
ssh -vT git@github.com
第三行左右应该这样说:
debug1: Connection to github.com [<ip address>] port <port num>
如果您没有尝试连接到 github.com,那么您的配置文件将指向您偏离方向。
事实证明,无论如何我都不需要配置文件中的任何内容,所以我可以安全地删除它。 如果你想维护一个配置文件,这里有一篇很好的文章:
http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/
此外,这些 GitHub 文档确实帮助我调试了我的问题:
https://help.github.com/articles/error-permission-denied-publickey
https://help.github.com/articles/what-ip-addresses-does-github-use-that-i-should-whitelist
添加新答案而不是编辑以获得更大的可见性,让任何遇到我遇到相同问题的人...
我正好相反。 用于工作的私有 Bitbucket 存储库和子模块。 老是出现这个错误...
fatal: repository 'http://bitbucket.org/companyname/submodule-repo-name.git' does not exist
fatal: clone of 'http://bitbucket.org/companyname/submodule-repo-name.git' into submodule path
'/Users/me/path/to/repo-using-submodule/folder' failed
Failed to clone 'submodule/folder'. Retry scheduled
fatal: repository 'http://bitbucket.org/companyname/submodule-repo-name.git' does not exist
fatal: clone of 'http://bitbucket.org/companyname/submodule-repo-name.git' into submodule path
'/Users/me/path/to/repo-using-submodule/folder' failed
Failed to clone 'submodule/folder' a second time, aborting
我不得不手动进入我的 .git/config 文件并更新它:
[submodule "submodule-name"]
url = https://bitbucket.org/companyname/submodule-repo.git
有了这个:
[submodule "submodule-name"]
url = git@bitbucket.org:companyname/submodule-repo.git
不知道如何设置以便我和我所有的同事无需调整即可使用子模块,但让我度过了几个月的挣扎。
弄清楚了。 .gitmodule 文件中的路径无法下载子模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.