执行 Windows 重新安装后,我在使用 github 设置 GPG 提交签名时遇到了一些问题。
问题:
提交时,GPG 签名失败并返回此错误:
gpg: skipped "993E2EFC8503C42F": No secret key
gpg: signing failed: No secret key
error: gpg failed to sign the data
fatal: failed to write commit object
我在谷歌上搜索到的有关此问题的所有内容都指向设置 gpg.program
到 GnuPG gpg 可执行文件的位置 ( "C:\Program Files (x86)\GnuPG\bin\gpg.exe"
) 遗憾的是,这并没有解决我的问题。
正在执行gpg --list-secret-keys --keyid-format=long
在 git bash 中返回我的 gpg key ,但是在 powershell 或 cmd 中执行相同的命令却没有,我相信这可能是我的问题,尽管我不知道如何解决这个问题。
已采取的步骤:
- 从here安装了GPG4Win
- 从 here 安装了 git
- 遵循 github 的 GPG 设置指南
- 设置
git config --global user.name "name..."
和git config --global user.email "email"
- 设置
git config --global user.signingkey
到我的 gpg key - 设置
git config --global gpg.program
至"C:\Program Files (x86)\GnuPG\bin\gpg.exe"
正如各种其他在线教程和答案所述 - 设置
git config --global commit.gpgsign
为真
- 已查看 "No secret key" error when signing git commit on Windows , gpg: skipped "N": secret key not available和 git commit signing failed: secret key not available
预期结果:
成功提交经过验证的提交
奖金信息
- Git 版本:2.36.0.windows.1
- 操作系统:Windows 11 22000.613
最佳答案
我已经弄清楚了!
我最终不太确定问题具体是什么,但是,在卸载 GPG4Win 和 Git,然后仅重新安装 Git 并完成 GPG 设置过程后,我现在能够执行经过验证的提交。这是使用 Gits 捆绑的 GPG 程序,没有其他 GPG 相关安装。
不确定这是否对其他人有帮助,但如果您在 Windows 上遇到此问题,请尝试在不安装 GPG4Win 的情况下运行 gpg 设置过程,并仅使用 gits 捆绑的 GPG 可执行文件。
记住将 commit.gpgsign
设置为 true 并告诉 git 你的签名 key ,就像 git config --global user.signingkey "your key id"
如果你只想要为特定项目设置签名 key ,您可以 cd 到项目目录并运行相同的命令,而不使用 --global
标记。
关于git - 使用 GPG 签署 git 提交的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72075234/