问题现象 1:
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
error: cannot run gpg: No such file or directory
error: gpg failed to sign the data
fatal: failed to write commit object
注意,此处有明显错误提示 error: cannot run gpg: No such file or directory
解决办法:
git config --global gpg.program "$(which gpg)"
echo "no-tty" >> ~/.gnupg/gpg.conf
问题现象 2:
error: gpg failed to sign the data
fatal: failed to write commit object
对于这种没有明显错误提示的提交异常,只能采用类似于 gpg debug 的方式
解决办法:
gpg --version
echo "test" | gpg --clearsign
- 执行
brew install gnupg gnupg2 pinentry-mac
- 然后继续尝试
echo "test" | gpg --clearsign
,并输入 mac 开机密码,非 gpg 密码 - 这时commit就可以带上gpg签名了
git commit -S -m "This is a test commit with gpg signing"
最后查看下本地的 git 环境配置
git config -l | grep gpg