gpg: keyblock 资源 pubring.kbx 未找到,因为 repo 路径以 gnupg 主页为前缀

gpg: keyblock resource pubring.kbx not found because the repo path is prefixed to the gnupg home

我曾经让我的提交由 gpg 签名,一切正常,但我突然收到这条消息:

gpg: keyblock resource '/c/Users/username/path/to/project/C:\Users\username\.gnupg/pubring.kbx': No such file or directory
gpg: skipped "my_key": No secret key
gpg: signing failed: No secret key
error: gpg failed to sign the data
fatal: failed to write commit object

注意keyblock资源的路径,由两条路径组成,确实无效。

关于我的设置的信息

我的提交自动签名,我的设置来自 , in summary: I set up gpg like normal, then installed gpg2 and pipe my passphrase into gpg every time using a shell file. And no, I didn't get gpg-agent to do this, though if you know how to do it please answer this question:

我有一个指向 C:\Users\username\.gnupg 的环境变量 GNUPGHOME。我尝试将其更改为 C:/Users/username/.gnupg 但错误中的斜线也发生了变化。我尝试将其更改为 /c/Users/username/.gnupg 但错误消息变为

gpg: Fatal: can't create directory '/c/Users/username/path/to/project/C:/Users/username/.gnupg': No such file or directory

我也不知道我的系统发生了什么变化导致了这个问题。

相关问题

这个问题非常相似,但路径不同,但没有解决:Git commit signing GPG issue 评论是检查 gitconfig 中的路径,但我在任何 gitconfig 中都没有 gnupg 目录的路径,而且我认为无论如何它都不会以 repo 的路径为前缀。我在主 ~\.gitconfig:

中有这个
[user]
    signingkey = my_key
[commit]
    gpgsign = true
[gpg]
    program = C:\Users\username\gpg-no-tty.sh

在这里也发现了同样问题的人:https://jira.atlassian.com/browse/SRCTREEWIN-8527

的标签描述中,我无法弄清楚这个问题是属于这里还是超级用户,因为我不确定这是程序化还是直接使用(两者都是?)。

我遇到了同样的问题。要修复它,我只需要在我的 .gitconfig 文件中指定 gpg.program 变量来指向我安装的 Gpg4win,如下所示:

git config --global gpg.program "%PROGRAMFILES(x86)%\GnuPG\bin\gpg.exe"

git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"

显然路径取决于您的 gpg 二进制文件所在的位置。一旦我这样做了,它就能够使用我的 GNUPGHOME 环境变量并找到我的系统密钥环用于签名。不过,这将使用 pinentry 提示您输入密钥密码。

我认为出现此问题是因为 Git for Windows 附带了默认使用的 gpg 版本。无论出于何种原因,当它执行命令以签署您的提交时,它似乎将本地回购路径作为 gpg 主目录路径的前缀。

希望这对您有所帮助

(请注意,我又遇到了同样的问题,但不得不以不同的方式解决)

您的 gpg 主目录一团糟,因为它试图在该目录中找到 pubring.kbx 文件。 gpg 可能会认为它的 homedir 是您执行 gpg 的路径,因此您会看到带有前缀的回购路径 - 不,我不知道为什么。

您可以使用 gpg 的 --homedir 选项解决这个问题。

  1. 告诉bash使用它:在C:\Users\username\.bash_profile中添加alias gpg="gpg --homedir=/c/Users/username/.gnupg"
  2. 告诉git使用它:创建一个文件C:\Users\username\start-gpg.sh并放入其中gpg --homedir=/c/Users/s156757/.gnupg "$@"。然后运行git config --global gpg.program C:\Users\username\start-gpg.sh告诉git使用它。
  3. 重新启动bash。

注意:为了对此进行测试,我使用了 git 附带的 gpg2。这可能就是 GNUPGHOME 变量没有做任何事情的原因——我没有单独安装 gnupg。