我参考了几篇关于Git 2.10发行说明中的漂亮属性的文章。将git升级到2.10.0,并对全局的.gitconfig进行了更改,结果如下-

[filter "lfs"]
    clean = git-lfs clean %f
    smudge = git-lfs smudge %f
    required = true
[user]
    name = xyz
    email = abc.def@gmail.com
    signingkey = AAAAAAA
[core]
    excludesfile = /Users/xyz/.gitignore_global
    editor = 'subl' --wait
[difftool "sourcetree"]
    cmd = opendiff \"$LOCAL\" \"$REMOTE\"
    path = 
[mergetool "sourcetree"]
    cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
    trustExitCode = true
[alias]
    lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
[color "diff"]
    old = red strike
    new = green italic

但是现在我尝试使用

git commit -a -S -m "message"

我看到下面的错误-

你需要一个密码来解锁秘钥 用户:“XYZ(数字签名)” 2048-bit RSA key, ID AAAAAAAA, created 2016-07-01 错误:GPG数据签名失败致命:写提交失败 对象

注意-我仍然可以使用git commit -a -m "message"来提交更改

有办法克服同样的问题吗?或者在gpg配置中需要做任何改变以适应git的升级?


更新1

还寻求进一步的有用性,以下是是否有一种方法在Git中使用GPG密钥“自动签名”提交?我已经配置了密钥使用

git config --global user.signingkey ED5CDE14(with my key) 
git config --global commit.gpgsign true

很明显得到了相同的错误。


当前回答

对于在MacOS机器上遇到此问题的任何人,请尝试以下方法:

brew uninstall gpg brew install gpg2 brew install pinentry-mac (if needed) gpg --full-generate-key Create a key by using an algorithm. Get generated key by executing: gpg --list-keys Set the key here git config --global user.signingkey <Key from your list> git config --global gpg.program /usr/local/bin/gpg git config --global commit.gpgsign true If you want to export your Key to GitHub then: gpg --armor --export <key> and add this key to GitHub at GPG keys: https://github.com/settings/keys (with START and END line included)

如果问题仍然存在:

Test -r ~/。bash_profile && echo 'export GPG_TTY=$(tty)' >> ~/.bash_profile

echo 'export GPG_TTY=$(tty)' >> ~/.profile

如果问题仍然存在:

安装https://gpgtools.org并通过从菜单栏按下sign来签署您使用的密钥:key -> sign

如果问题仍然存在:

转到:⁨你的全局。gitconfig文件,在我的例子中是:⁨/Users/gent/.gitconfig 并修改.gitconfig文件(请确保Email和Name与您在生成Key时创建的相同):

(用户) 邮箱= gent@youremail.com name = Gent signingkey = <YOURKEY> (gpg) 程序= /usr/local/bin/gpg (提交) Gpsign = true Gpgsign = true (过滤“lfs”) Process = git-lfs filter-process Required = true 清洁= git-lfs清洁——%f 涂抹= git-lfs涂抹——%f (证书) Helper = osxkeychain

其他回答

以上都不适合我,我通常使用我的IDE终端。

我时不时地得到这个错误,在大多数情况下,它工作得很好。 我在跑步后发现了这个问题

 echo "test" | gpg --clearsign

gpg: signing failed: Screen or window too small
gpg: [stdin]: clear-sign failed: Screen or window too small

解决方案:增加终端窗口大小。

如果gnupg2和gpg-agent 2。如果使用了x,请务必设置环境变量GPG_TTY。

export GPG_TTY=$(tty)

有关常见问题,请参阅GPG的文档。

除了没有使用git正确设置gpg密钥外,另一个可能的问题是: 试图通过X转发在ssh会话中提交。 在这种情况下,它可以尝试调用一个GUI,如果没有设置env var DISPLAY,将会失败。

通过编辑~/.gnupg/gpg-agent.conf,可以强制gpg-agent使用ty-only工具:

pinentry-program /usr/bin/pinentry-tty

然后重新加载conf:

gpg-connect-agent reloadagent /bye

(当然先安装pinentry-tty)

如果你像我一样将WSL与IDE一起使用,你可能会遇到这个问题,因为使用IDE的提交接口提交时,密码“窗口”从未显示(WSL还不支持GUI应用程序)。

修复方法是简单地使用命令行git,因为它有自己的cli窗口供您输入密码。你还需要确保终端的“大”足以弹出(令人惊讶的是我知道)

在prezto的另一个zsh变体中遇到了这个。那里的问题是我的git回购是新的,没有node_modules添加到.gitignore。当我将node_modules添加到.gitignore时,问题就没有了。所以我的假设是git-info由于这些大的node_module而花费时间。