如何 Git 上使用 GPG 进行验证提交教程
2019-11-18T17:07:49
首先你可以可以参阅 Gitee(码云) 和github发布的各自平台的添加教程
https://gitee.com/help/articles/4248#article-header0
https://help.github.com/en/github/authenticating-to-github/managing-commit-signature-verification
以下来自码云
如何在码云上使用 GPG
GPG Key 生成与导出
Windows
- 下载 https://gpg4win.org/
- 生成 GPG Key

输入用户名和邮箱,注意邮箱必须与 Gitee 提交邮箱一致

- 导出

另外在Windows平台请注意
请仔细确认你的GPG 主目录是在哪个位置,如下图:

比如我的就是
C:/Users/Yanlongli/AppData/Roaming/gnupg/pubring.kbx
而 Git默认寻找位置是
C:\Users\Yanlongli\.gnupg
这会产生如下问题
gpg: directory '/c/Users/Yanlongli/.gnupg' created
gpg: keybox '/c/Users/Yanlongli/.gnupg/pubring.kbx' created
gpg: skipped "68EFDB840679A70E": No secret key
gpg: signing failed: No secret key
error: gpg failed to sign the data
fatal: failed to write commit object
这就是目录不对
我们可以通过软连接的方式链接到该目录 -- 注意需要管理员权限
mklink /d C:\Users\Yanlongli\.gnupg C:\Users\Yanlongli\AppData\Roaming\gnupg

如果出现如下错误,直接删除 所有 .gnupg 目录下 .lock结尾的文件即可
gpg: invalid size of lockfile '/c/Users/Yanlongli/.gnupg/gnupg_spawn_agent_sentinel.lock'
gpg: cannot read lockfile
gpg: can't connect to the agent: Invalid argument
gpg: keydb_search failed: No agent running
gpg: skipped "68EFDB840679A70E": No agent running
gpg: signing failed: No agent running
error: gpg failed to sign the data
fatal: failed to write commit object