14

我试图用该命令签署我的提交,git commit -S但它没有提示我输入 GPG 密钥的密码就失败了。

错误是:

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

我注意到如果我之前运行以下命令git commit -S

gpg -o /dev/null --local-user MY_KEY_ID -as <(echo 1234) && echo "The correct passphrase was entered for this key"

...一切正常,我的提交已正确签名。我认为这是因为我的密码被缓存了,但这不是我期望的行为。

我希望每次我想签署提交或标签时,Git 都会提示我输入密码。

在这个问题上找到了“解锁我的密钥”的命令:How to use gpg command-line to check passphrase is correct

4

1 回答 1

14

您可能需要告诉pinentrygpg 用来提示您输入密码的软件,在哪里提示您。

export GPG_TTY=$(tty)
git commit -S

如果这可行,我建议GPG_TTY在你的 shell 的“rc”文件中导出。

gpg-agent 文档关于GPG_TTY

于 2018-04-03T15:21:29.837 回答