安装gpg windows https://www.gpg4win.org/
生成密钥
查看密钥
导出公钥 1 gpg --export --armor 邮箱 > 公钥文件名
导入公钥
签名
验证
配置git 1 2 3 4 5 6 7 8 git config --global user.signingkey 密钥ID git config --global commit.gpgsign true # 配置gpg程序路径 git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe" # 配置git提交签名 git config commit.gpgsign true
密钥ID为上一步生成的密钥ID的后8位
在路径C:\Users\Administrator
下找到 .gitconfig
,复制一份,重命名为 .gitconfig-gitlab
,
.gitconfig
内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [user] name = xxxxxx email = xxxxxx@qq.com # The contents of this file are included only for GitLab.com URLs [includeIf "hasconfig:remote.*.url:https://gitlab.xxxxx.com/**"] # Edit this line to point to your alternative configuration file path = ~/.gitconfig-gitlab [includeIf "hasconfig:remote.*.url:https://github.com/**"] path = ~/.gitconfig-github [commit] gpgsign = false [gpg] program = C:\\Program Files (x86)\\GnuPG\\bin\\gpg.exe
.gitconfig-gitlab
内容如下:
1 2 3 4 5 6 7 [user] name = xx email = xxx@xxx.com signingkey = 密钥ID [commit] gpgsign = true
配置github
复制公钥
登录github
Settings -> SSH and GPG keys -> New GPG key
粘贴公钥
测试
推送
查看 1 git log --show-signature