为什么 commit 没有 Verified 标志
2026年5月5日 · 471 字
为什么 commit 没有 Verified 标志
Commit 签名这件事,很多人卡在三个概念的混淆上:Authentication Key、Signing Key、GPG key。一次说清楚。
HTTPS 还是 SSH,跟 Verified 没关系
先把这个误解拆掉。
GitHub 上 commit 显示 Verified,只跟你有没有对 commit 做签名有关,跟 push 时走的是 HTTPS 还是 SSH 没有任何关系。
查看当前 push 方式:
git remote -v
- 显示
git@github.com:...→ SSH - 显示
https://github.com/...→ HTTPS
两者的区别只在传输层做身份验证,和签名是两回事。
三种 key,干什么用
| 类型 | 干什么 | GitHub 设置位置 |
|---|---|---|
| Authentication Key | 证明"你是你",push/pull 时验证身份 | Settings → SSH keys |
| Signing Key | 对 commit 内容签名,证明"这个 commit 是你写的" | Settings → SSH signing keys 或 GPG keys |
类比一下:Authentication key 是门禁卡,用来进门;Signing key 是亲笔签名,用来证明文件是你签的。两件事可以用同一把 key,也可以分开配置。
GPG key 和 SSH key 的区别
GPG key 来自 GNU Privacy Guard,基于 OpenPGP 标准;SSH key 就是通常配 GitHub 用的那种。功能上有重叠但不完全一样:
- SSH key 能做的事:身份认证(push/pull)、签名 commit(2022 年 GitHub 加入)
- GPG key 能做的事:签名 commit、加密文件/邮件
Git 最早只支持 GPG 签名,所以很多老教程会教你装 GPG。但 GitHub 现在支持直接用 SSH key 签名,不需要额外装 GPG,更简单。
复用一个 SSH key 做签名
你的 SSH key 可以同时用于认证和签名。在 GitHub 上把同一个公钥再添加一次,Key type 选 Signing Key,然后本地配三条命令:
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign true
之后的 commit 就会显示 Verified。
验证配置:
git config --global --list | grep sign
没有任何输出,说明签名还没开。