如何让 VSCode (及其他的 GUI 程序) 中的 Git 支持 GPG 签名?

2017-08-25 18:47:08 +08:00
 ysc3839

Git 设置 commit.gpgsign=true 后 commit 的时候会提示输入 GPG 的密码并自动签名。

但是开启这个选项后在 VSCode 里 commit 时就会出错,提示 gpg: cannot open tty 'no tty': No such file or directory,该怎么设置才能让其支持?

另外,开启后在 Visual Studio 中 commit 是会有个窗口提示输入密码的。

4451 次点击
所在节点    问与答
5 条回复
ysc3839
2017-08-25 19:16:01 +08:00
搜索到了这个 https://jamesmckay.net/2016/02/signing-git-commits-with-gpg-on-windows/

git config --global gpg.program "C:/Program Files (x86)/GNU/GnuPG/gpg2.exe"

设置后确实有效,但是这么做的话 CLI 里面也会出现 GUI 提示。很好奇 VS 是怎么实现的?
jsw
2017-08-25 19:29:22 +08:00
一般 Git 安装自己 bundle 了一套 GPG,这套应该是不带 pinentry,密码直接从 stdin 里读,所以要 TTY
但是 GPG4win 套件是有 pinentry 的(就是那个输入密码框),就搞定了那个问题

config 到 global 之后 git 默认都会调取 GPG4win 里的 gpg,所以就蹦 GUI 提示了。
jsw
2017-08-25 19:30:50 +08:00
原文引用:
```
jsw
2017-08-25 19:31:02 +08:00
```
Git comes with its own version of gpg.exe, but it is the MinGW version — a direct port of the Linux version, which saves your keychain in the ~/.gnupg folder in your home directory. The gpg4win port, on the other hand, saves your keychain in ~/AppData/Roaming/GnuPG. Certificates managed by one won ’ t be seen by the other. You will also need to use the gpg4win version if you want to use a GUI such as SourceTree, since the MinGW version of gpg.exe is entirely command line based and doesn ’ t play nicely with Git GUIs. By contrast, the gpg4win version brings up a dialog box to prompt for your password.
```
ysc3839
2017-08-25 19:43:47 +08:00
@jsw 用 Process Explorer 看了一下,Git 确实使用了自带的 GPG。
VS 自己也带了一份 Git,里面没有带 GPG,所以使用了 Gpg4Win 的 GPG,于是就有 GUI 提示了。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/385817

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX