我刚开始使用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

请注意,由于这里和这里的问题存在安全问题,不建议这样做

其他回答

使用GIT_TRACE=1查看Git失败的地方,然后检查Git使用的所有自定义配置以及它们定义的地方,然后根据您的需要覆盖:

GIT_TRACE=1 git commit -S -m "this will tell you wich intern git command failed"

git config --list --show-scope --show-origin

对我来说,我有错误:gpg未能签署数据和致命:未能写入提交对象,因为Git默认使用smimesign,即使我取消设置gpg.x509。程序钥匙,smimesign找不到我的钥匙。

所以我必须显式地告诉Git使用gpg:

git config --local gpg.x509.program gpg

可能你的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

解决方案:

Issue: Disabled loopback pinentry mode

要解决这个问题,你需要在~/.gnupg/gpg.conf中启用环回pinentry模式:

cat <<'EOF' >> ~/.gnupg/gpg.conf

use-agent 
pinentry-mode loopback

EOF

还有~/.gnupg/gpg-agent.conf(如果文件不存在就创建文件):

cat <<'EOF' >> ~/.gnupg/gpg-agent.conf

allow-loopback-pinentry

EOF

然后使用echo RELOADAGENT | gpg-connect-agent重新启动代理,您应该可以运行了!

我解决了安装brew install gpg2然后做git配置——global gpg的问题。程序gpg2

我正在使用它。它支持zsh和工作在Windows子系统Linux:

export GPG_TTY=$(tty)

其他用户已经确认以上是MacOS(例如Catalina 10.15.7)所需的唯一更改。对于mac,将以上内容添加到~/.zshrc。

在使用WSL2的Windows中的Linux容器中也可以工作。