我刚开始使用git,我通过自制软件安装git和gpg。 由于某种原因,当我提交git时,我得到了这个错误 我看了很多关于这个话题的stackoverflow问题,但没有一个对我有用。 如何修复此错误以成功上传?
error: gpg failed to sign the data
fatal: failed to write commit object
我刚开始使用git,我通过自制软件安装git和gpg。 由于某种原因,当我提交git时,我得到了这个错误 我看了很多关于这个话题的stackoverflow问题,但没有一个对我有用。 如何修复此错误以成功上传?
error: gpg failed to sign the data
fatal: failed to write commit object
当前回答
参考@sideshowbarker和@Xavier Ho解决方案,我通过以下步骤解决了我的问题。
假设gpg2通过brew安装,
git config --global gpg.program gpg2
brew install pinentry
gpgconf --kill gpg-agent
gpg2 -K --keyid-format SHORT
// no key found then generate new one
gpg2 --gen-key
gpg2 -K --keyid-format SHORT
... - dpg gnupg - pubring。
sec rsa2048/0A61C6FC 2017-06-29 [SC][有效期:2019-06-29]
git config --global user.signingkey 0A61C6FC
经同事提醒,需要追加
export GPG_TTY=$(tty)
~ /。ZSHRC如果使用zsh,否则追加到~/.bash_profile
For macOS,
gpg2在brew中与GPG结合,因此GPG命令指向gpg2
brew install gpg2
酿造信息GPG
Gnupg:稳定2.2.6(瓶装)
git config --global gpg.program gpg
gpg -K --keyid-format SHORT
还有pinentry-mac用于密码输入
brew install pinentry-mac
vim ~/.gnupg/gpg-agent.conf
添加一行
pinentry-program /usr/local/bin/pinentry-mac
经同事提醒,需要追加
export GPG_TTY=$(tty)
~ /。ZSHRC如果使用zsh,否则追加到~/.bash_profile
其他回答
在我的例子中,我混合了提交签名文档中给出的gpg配置和smimesign配置:https://help.github.com/en/github/authenticating-to-github/telling-git-about-your-signing-key
在工作了几个小时之后,我发现纠正它的最好方法是取消与gpg相关的所有内容,并重新配置gpg。
正如在@Jason Thrasher的回答中提到的,使用以下方法找到所有与gpg相关的git配置:
git config -l | grep gpg
然后取消所有的golable以及本地使用:
git config --global --unset <config_name>
git config --local --unset <config_name>
然后按照上面给出的官方文档重新配置。 希望这能有所帮助。
经过大量搜索,我发现gpg密钥是我的情况下的问题。
如果您的gpg密钥正确,您可以尝试运行gpg——status-fd=2 -bsau <您的gpg密钥>。
要更新正确的密钥,请执行以下操作: 检查密钥使用:GPG——list-secret-keys——keyid-format=long
它应该有以下输出:
/Users/hubot/.gnupg/secring.gpg
------------------------------------
sec 4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]
uid Hubot
ssb 4096R/42B317FD4BA89E7A 2016-03-10
然后更新密钥使用:
git config --global user.signingkey 3AA5C34371567BD2
现在再次检查提交,如果关键字是问题,它应该成功。您需要设置密码短语来更新密钥,您可以使用GitHub文档进行更新。
更多详情见:https://gist.github.com/paolocarrasco/18ca8fe6e63490ae1be23e84a7039374
这将帮助你摆脱它
Git配置提交。gpgsign假
我在linux/windows平台上都有这个问题,在我的情况下,我只需要更仔细地注意输出。这是令人难以置信的,因为我可以使用相同的设置在其他回购中签署提交。
git commit -m "test signing"
gpg: skipped "***63231079***": No secret key
gpg: signing failed: No secret key
error: gpg failed to sign the data
fatal: failed to write commit object
我强调了“跳过”这一行。请注意,有时当你克隆一个回购时,他们会分配一个密钥:这个问题让我很困惑,以至于我破坏了我可以访问的分叉回购,并在github上重新分叉。然后因为我在想“全局配置”,我从来没有想过要看本地回购配置,当我注意到这一点:
[user]
signingkey = 63231079
嗯,当然它不会工作nimrod, git默认为本地设置,所以这就是为什么你的密钥永远不会被拾取。我通过git配置设置指针,它一直在工作。
如果您使用智能卡/yubikey存储您的GPG密钥,并且您通过存储在卡中的密钥设置了git配置的signkey(并且上面所有的答案似乎都不能解决您的问题),您的卡的PIN被阻塞可能是这个问题的根本原因。
检查被阻止的PIN码:
gpg --card-status
如果计数器类似于
Reader ...........: Yubico YubiKey
PIN retry counter : 3 0 3
然后你的PIN被阻止(3次不成功尝试后)。
解锁密码:
gpg --card-edit
gpg/card> admin
Admin commands are allowed
gpg/card> passwd
gpg: OpenPGP card no. … detected
1 - change PIN
2 - unblock PIN
3 - change Admin PIN
4 - set the Reset Code
Q - quit
Your selection? 2
PIN unblocked and new PIN set.
1 - change PIN
2 - unblock PIN
3 - change Admin PIN
4 - set the Reset Code
Q - quit
Your selection? q