使用 GIT 更新子模块时出现致命错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8197089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal Error when updating submodule using GIT
提问by Devin Dixon
I am trying to update the submodules of this git repositary but I keep getting a fatal errors:
我正在尝试更新此 git 存储库的子模块,但我不断收到致命错误:
[root@iptlock ProdigyView]# git submodule update --recursive
Cloning into core...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Clone of '[email protected]:ProdigyView/ProdigyView-Core.git' into submodule path 'core' failed
Or this way
或者这样
[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' ([email protected]:ProdigyView/ProdigyView-Core.git) registered for path 'core'
Cloning into core...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Clone of '[email protected]:ProdigyView/ProdigyView-Core.git' into submodule path 'core' failed
Any ideas of why this is happening withthe submodule? The repo is this one:
关于子模块为什么会发生这种情况的任何想法?回购是这样的:
https://github.com/ProdigyView/ProdigyView
https://github.com/ProdigyView/ProdigyView
(The submodule is able to be cloned if I do not try to clone it as a submodule.)
(如果我不尝试将其克隆为子模块,则可以克隆该子模块。)
采纳答案by Devin Dixon
Figured it out. The path in the .gitmodule files could not download the submodule.
弄清楚了。.gitmodule 文件中的路径无法下载子模块。
回答by Dani?l W. Crompton
The issue is that git can't find the public key needed to download the repo from your server, the solution is to use the public url.
问题是 git 找不到从您的服务器下载 repo 所需的公钥,解决方案是使用公共 url。
In the file .gitmodule you will find the following entry:
在文件 .gitmodule 中,您将找到以下条目:
[submodule "example"]
path = example
url = [email protected]:webhat/example.git
The URL need to be changed to the public URL for the module:
URL 需要更改为模块的公共 URL:
[submodule "example"]
path = example
url = https://github.com/webhat/example.git
As you can see the prefix git@has been changed to https://and the infix :becomes /
如您所见,前缀git@已更改为https://并且中缀:变为/
EDIT:In your own repository you might need to use git://
rather than https://
编辑:在您自己的存储库中,您可能需要使用git://
而不是https://
The previous answer was unclear to me, so I added this.
之前的答案对我来说不清楚,所以我添加了这个。
EDIT 2:If you find you need to run git submodule sync
or need to edit .git/config
to get this to work, you have likely set up remotes for the submodules.
编辑 2:如果您发现需要运行git submodule sync
或需要编辑.git/config
才能使其工作,您可能已经为子模块设置了遥控器。
回答by Temi
If it can help some people:
如果它可以帮助某些人:
I update my .gitmodules
我更新了我的 .gitmodules
[submodule "example"]
path = example
url = https://github.com/webhat/example.git
Then I update my .git/config too
然后我也更新了我的 .git/config
[submodule "example"]
url = https://github.com/webhat/example.git
Like some of you said it before (and I thank you).
就像你们中的一些人之前说过的那样(我感谢你们)。
Then I update my .git/modules/example/config
然后我更新我的 .git/modules/example/config
[remote "origin"]
fetch = [...]
url = https://github.com/webhat/example.git
And to finish I do
为了完成我做
git submodule sync
git submodule init
git submodule update
回答by RC_02
You can manually pass in the key in Build --> "Execute shell" section of jenkins job :
您可以在 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 {path_to_private_key}; git submodule update --init --recursive'
Example:
例子:
ssh-agent bash -c 'ssh-add /var/lib/jenkins/.ssh/jenkins_rsa; git submodule update --init --recursive'
ssh-agent bash -c 'ssh-add /var/lib/jenkins/.ssh/jenkins_rsa; git submodule update --init --recursive'
回答by hmedia1
This is happened that many times for me that I put a function in my .bash_profile (works on BSD sed / GNU / Mac):
这对我来说发生了很多次,我在我的 .bash_profile 中放置了一个函数(适用于 BSD sed / GNU / Mac):
gitfix () {
if [ -f "./.gitmodules" ] ; then
sed -E -i.bak -e "s/(url *= *)(.*:)(.*)/https:\/\/github.com\//g" .gitmodules \
git submodule sync
git submodule update --init --recursive
fi
}
A one liner:
一个班轮:
sed -E -i.bak -e "s/(url *= *)(.*:)(.*)/https:\/\/github.com\//g" .gitmodules ; git submodule sync ; git submodule update --init --recursive
vim search/replace:
vim 搜索/替换:
%s/\(url\s*=\s*\)\(.*:\)\(.*\)/https:\/\/github.com\//
Underlying solution based on Dani?l 's answer
基于 Dani?l 的答案的基础解决方案
回答by Sruthi
The following steps will fix the problem.
以下步骤将解决该问题。
- Delete the folder of the submodule on your local.
- Do
git submodule sync
- then
git submodule update --init
- 删除本地子模块的文件夹。
- 做
git submodule sync
- 然后
git submodule update --init
Hope this helps.
希望这可以帮助。
回答by Kio Krofovitch
I had this same issue. However, in my situation, the team wantedto use the SSH access from the .gitmodules, so modifying the URL to use http:// was not an option.
我有同样的问题。但是,在我的情况下,团队希望使用来自 .gitmodules 的 SSH 访问,因此修改 URL 以使用 http:// 不是一个选项。
Ultimately, my issue was having an incorrect ~/.ssh/config file. The config file had some erroneous settings, so I was actually trying to access the incorrect server every time I'd really want to access [email protected]. I found this out by executing the following command:
最终,我的问题是 ~/.ssh/config 文件不正确。配置文件有一些错误的设置,所以每次我真的想访问 [email protected] 时,我实际上都试图访问错误的服务器。我通过执行以下命令发现了这一点:
ssh -vT [email protected]
The third line or so should say this:
第三行左右应该这样说:
debug1: Connection to github.com [<ip address>] port <port num>
If you aren't attempting to connect to github.com, then your config file is pointing you off course.
如果您没有尝试连接到 github.com,那么您的配置文件将指向您偏离方向。
Turns out I didn't need any of the stuff in my config file anyway, so I was safe to delete it. If you want to maintain a config file, here is a good article on that:
事实证明,无论如何我都不需要配置文件中的任何内容,所以我可以安全地删除它。如果你想维护一个配置文件,这里有一篇很好的文章:
http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/
http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/
Also, these GitHub docs really helped me debug my issue:
此外,这些 GitHub 文档确实帮助我调试了我的问题:
https://help.github.com/articles/error-permission-denied-publickey
https://help.github.com/articles/error-permission-denied-publickey
https://help.github.com/articles/what-ip-addresses-does-github-use-that-i-should-whitelist
https://help.github.com/articles/what-ip-addresses-does-github-use-that-i-should-whitelist
回答by MayTheSForceBeWithYou
Adding new answer instead of edit for greater visibility to anyone experience the same problem I was...
添加新答案而不是编辑以提高可见性,让任何遇到我遇到相同问题的人...
I had the exact opposite. Private Bitbucket repo & submodule for work. Always got this error...
我正好相反。用于工作的私有 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
I had to manually go into my .git/config file and update this:
我不得不手动进入我的 .git/config 文件并更新它:
[submodule "submodule-name"]
url = https://bitbucket.org/companyname/submodule-repo.git
with this:
有了这个:
[submodule "submodule-name"]
url = [email protected]:companyname/submodule-repo.git
Not sure how to set this up so me and all my coworkers can use the submodule without tweaking, but got me past my several month long struggle with this.
不知道如何设置以便我和我所有的同事无需调整即可使用子模块,但让我度过了几个月的挣扎。