我刚开始使用git,我通过自制软件安装git和gpg。 由于某种原因,当我提交git时,我得到了这个错误 我看了很多关于这个话题的stackoverflow问题,但没有一个对我有用。 如何修复此错误以成功上传?

error: gpg failed to sign the data
fatal: failed to write commit object

当前回答

如果您使用智能卡/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

其他回答

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

export GPG_TTY=$(tty)

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

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

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

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

当GPG密钥过期时,也会发生此错误。生成一个新密钥并将其添加到Git中应该可以解决这个问题。

为我解决这个问题的方法是确保密钥的名称与我的git用户名匹配。我猜邮件也要匹配。这可能与我在Mac上使用GPG钥匙串有关。不确定。

当我填写这个时,我以为我是在命名密钥,但我猜它是在询问我的名字(git用户名)。