Git GPG:gpg无法签署数据。

4

我在使用git commit -S -m 'test'签署提交时遇到了错误,出现以下错误:

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

我已经尝试过这个解决方案,但仍然无法正常工作。

还尝试了这个,但仍然没有任何效果。

我使用的是最新版本的macOS Macbook Pro 2017。

是否有其他解决方案可以修复此问题,并正确提交我的提交到Github或Gitlab?


请添加使用gpg显示您的密钥的结果;我怀疑密钥已过期。 - U. Windl
@gpg用户U.Windl,gpg密钥今天已创建并设置。它仍然可能过期吗?如果是,我该如何检查它? - Matúš Rebroš
通过 GIT_TRACE=1 git commit -S -m 'test' 命令,Git 是否会显示有关 GnuPG 调用的确切信息? - Nickolay Olshevsky
@NickolayOlshevsky 终端显示如下。16:27:37.452431 git.c:455 trace: built-in: git commit -S -m test 16:27:37.466454 run-command.c:668 trace: run_command: gpgsm --status-fd=2 -bsau xxxxxxxxxxxxxxx 错误:gpg 无法签署数据 致命错误:无法写入提交对象 - Matúš Rebroš
看起来你正在尝试使用S/MIME而不是OpenPGP签名,这是有意为之吗?这篇文章应该对进一步的故障排除有所帮助:https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key - Nickolay Olshevsky
这个回答解决了您的问题吗? 'Git: gpg failed to sign the data'在Visual Studio Code中 - starball
4个回答

6

我遇到了同样的问题,我通过以下步骤解决:

  1. 首先确保密钥还未过期:gpg --list-keys
  2. 如果密钥仍然有效,请重新启动gpg-agent:gpgconf --kill gpg-agent
  3. 现在应该可以正常工作了。

1

0
首先,确保使用Git 2.40(2023年第一季度),这将澄清错误信息。
Git 2.36 (Q2 2022) 还改进了这种用例:GPGSM 的新版本以一种不向后兼容的方式更改了其输出,以破坏我们解析其输出的代码。
已经进行了调整以适应这些变化。

查看提交 b0b70d5提交 fa47dd6(2022年3月4日)由Todd Zullinger(tmzullinger提交。
查看提交 a075e79(2022年3月4日)由Fabian Stelzer(FStelzer提交。
(由Junio C Hamano -- gitster --合并于提交 21b839e,2022年3月13日)

gpg-interface/gpgsm:v2.3修复

协助者:Junio C Hamano
协助者:Todd Zullinger

Checking if signing was successful will now accept '[GNUPG]: SIG_CREATED' on the beginning of the first or any subsequent line.
Not just explictly the second one anymore.

Gpgsm v2.3 changed its output when listing keys from fingerprint to sha1/2 fpr.
This leads to the gpgsm tests silently not being executed because of a failed prerequisite.
Switch to gpg's --with-colons output format when evaluating test prerequisites to make parsing more robust.
This also allows us to combine the existing grep/cut/tr/echo pipe for writing the trustlist.txt into a single awk expression.

git merge --no-ff -m msg signed_tag_x509_nokey &&
GNUPGHOME=. git log --graph --show-signature -n1 plain-x509-nokey

0

我已经在我的Windows PC上安装了GPG,gpg --list-keys可以成功地列出我的密钥在Git Bash中(而不是标准的Windows命令行),然而,GitHub Desktop对我来说无法工作。

解决方案是将Git的GPG二进制文件添加到我的PATH变量中。所以我将C:\Program Files\Git\usr\bin添加到了PATH中,然后GitHub Desktop开始工作。

注意:如果你在电脑上安装了Git,你很可能已经在这个路径下安装了GPG:C:\Program Files\Git\usr\bin\gpg.exe


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接