在我的机器上,我已经在 中设置了一个全局 git 用户~/.gitconfig,其中包含我的私人详细信息:
[user]
name = ebosi
email = me@private-email.com
signingkey = 0123456789ABCDEF
Run Code Online (Sandbox Code Playgroud)
但是,我希望这些全局设置被某些特定存储库中的其他凭据(例如工作凭据)覆盖。在这种情况下,我编辑本地 git 配置(例如~/work/project/.git/config),如下所示:
[user]
name = ebosi
email = ebosi@corporate.com
signingkey = FEDCBA9876543210
Run Code Online (Sandbox Code Playgroud)
我想使用正确的身份对我的提交进行 GPG 签名:默认为私有身份,除非在存储库配置中被覆盖。
但是,当我 时git commit -sS,git 正确地获取了签核身份,但没有获取 gpg 密钥。要使用我的公司密钥签署提交,我需要git commit -s -SFEDCBA9876543210
如何让 git 自动选择正确的 gpg 密钥?
(即 if 存在中定义的签名密钥./.git/config,否则 中定义的签名密钥~/.gitconfig)