Git 设置 commit.gpgsign=true
后 commit 的时候会提示输入 GPG 的密码并自动签名。
但是开启这个选项后在 VSCode 里 commit 时就会出错,提示 gpg: cannot open tty 'no tty': No such file or directory
,该怎么设置才能让其支持?
另外,开启后在 Visual Studio 中 commit 是会有个窗口提示输入密码的。
1
ysc3839 OP 搜索到了这个 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 是怎么实现的? |
2
jsw 2017-08-25 19:29:22 +08:00 1
一般 Git 安装自己 bundle 了一套 GPG,这套应该是不带 pinentry,密码直接从 stdin 里读,所以要 TTY
但是 GPG4win 套件是有 pinentry 的(就是那个输入密码框),就搞定了那个问题 config 到 global 之后 git 默认都会调取 GPG4win 里的 gpg,所以就蹦 GUI 提示了。 |
3
jsw 2017-08-25 19:30:50 +08:00
原文引用:
``` |
4
jsw 2017-08-25 19:31:02 +08:00 1
```
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. ``` |