我遇到了类似的问题,我按照 @theminer3746 的答案解决了它。
我能够通过以下步骤修复没有tty错误并有一个对话框来输入密码
([您的主目录]/.gnupg/secring.gpg)
git config --global gpg.program "c:\Program Files (x86)\GnuPG\bin\gpg.exe"
好的,答案既是肯定的也是否定的。
我想出的解决方法如下(假设您已经设置了GPG密钥,如果没有,请参考GitHub的设置教程)
(如果您还没有安装)
从PowerShell中(或者您可以使用Sourcetree中的内置终端),输入git config commit.gpgsign true
- 这将配置git自动签署当前存储库中的所有提交。
git config --global commit.gpgsign true
。
注意:如果您选择跳过第3步,请确保每次提交时都添加-S
(git commit -S
),否则您的提交将不会被签署。
当然,这种方法有一个缺点。
每次提交都必须在终端中执行。如果尝试使用sourcetree的提交按钮进行提交,将会出现错误。
gpg: cannot open tty `no tty': No such file or directory
error: gpg failed to sign the data
fatal: failed to write commit object
$ git config commit.gpgsign true
为了签署提交,您需要拥有GPG签名密钥。使用以下命令检查现有密钥:
$ gpg --list-secret-keys --keyid-format LONG
/Users/hubot/.gnupg/secring.gpg
------------------------------------
sec 4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]
uid Hubot
ssb 4096R/42B317FD4BA89E7A 2016-03-10
3AA5C34371567BD2 是您的签名密钥。
接下来,请执行以下命令:
$ git config commit.signingkey YOUR_KEY_HERE
如果您想为每个存储库签名,则在上述命令中添加--global
标志。例如,
$ git config --global commit.gpgsign true
$ git config --global commit.signingkey YOUR_KEY_HERE
无需下载其他软件即可签署您的提交。
打开存储库中 .git 文件夹中的配置文件,并添加/更新以下选项。
[commit]
gpgsign = true
signingkey = YOUR_KEY_HERE
secring.gpg
文件。这似乎是随着 GnuPG 2.1 版本更改而来的。解决方法是在 Git Bash 中使用以下命令自己创建此文件:gpg --export-secret-keys >~/.gnupg/secring.gpg
(感谢 rtyley)。之后,Kleopatra 中的导入应该可以正常工作。 - daimpi