我刚开始使用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
当前回答
这在ubuntu 18.04上对我有效
检查你的gpg密钥
gpg -K --keyid-format LONG
如果得到空白响应,则生成一个GPG密钥
gpg --generate-key
重新运行第一个命令,你应该得到一个输出:
sec rsa3072/95A854E0593B3214 2019-05-06 [SC] [expires: 2021-05-05]
AF2F7514568DC26B0EB97B9595A854E0593B74D8
uid [ultimate] yourname<your_email>
ssb rsa3072/EFD326E6C611117C 2019-05-06 [E] [expires: 2021-05-05]
设置git签名密钥
git config --global user.signingkey 95A854E0593B3214
然后你就可以开始了!(——global是可选的)
或者,如果您不介意用ssh密钥签名
git config commit.gpgsign false
请注意,由于这里和这里的问题存在安全问题,不建议这样做
其他回答
参考@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
我在升级到gnupg 2.x后遇到了这个问题。可以看到gpg2以不同的方式引用键:在~/.gitconfig中仍然有signingkey = ABC98F11 (gpg v1设置)。gpg2的键标识符较长。用gpg -list-secret-keys查找
可能你的Git配置设置为gpgsign = true。如果你不想指定你的提交,试着把它设置为false。转到存储库文件夹并更改该文件
纳米git -配置。
从这个……
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@bitbucket.org:yourrepo/project.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[user]
signingkey = <GPG-KEY>
[commit]
gpgsign = true
这……
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@bitbucket.org:yourrepo/project.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[user]
signingkey = <GPG-KEY>
[commit]
gpgsign = false
在我的情况下,我必须将存储在GitHub设置中的名称与键的名称和注释匹配。
所以如果gpg——list-keys返回uid [ultimate] Joe Blogs(花式注释)<email@example.com>你在.gitconfig中的名字应该是Joe Blogs(花式注释)。
最初,我将自己的名字设置为Joe Blogs, GPG不会找到我的密钥,并在strace中显示“无密钥”错误。不幸的是,如果没有strace,该错误就不会出现,并且会得到泛型
error: gpg failed to sign the data
fatal: failed to write commit object
对于我的带有GUI和gpg 2.2.19的Linux系统,无论是杀死gpg-agent(它会重新启动自己),取消$DISPLAY或设置$GPG_TTY都对我有效,因为它试图使用pinentry-gnome从控制台询问密码。我的钥匙还没有过期。
从一个超级用户的回答类似的问题,如何迫使GPG使用控制台模式pinentry提示密码?,如果您的系统有GNOME之类的GUI,并且包管理器配置为使用GUI pinentry程序,也会出现这个问题,这就是它挂起的原因。
我不得不切换到pinentry-tty来让GPG再次对消息进行签名。在Ubuntu上,这可以通过下面链接中的步骤来完成:
sudo apt install pinentry-tty
sudo update-alternatives --config pinentry
第二个命令将向您显示pinentry程序列表,并要求您输入一个数字来选择一个,因此键入与pinentry-tty对应的数字,然后无需任何额外的工作,签名消息(和git提交)将再次工作。