V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
ysc3839
V2EX  ›  问与答

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

  •  
  •   ysc3839 · 2017-08-25 18:47:08 +08:00 · 4407 次点击
    这是一个创建于 2407 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    第 1 条附言  ·  2017-08-25 20:09:04 +08:00
    已解决。
    用 Process Explorer 看了一下,Git 确实使用了自带的 GPG。
    VS 自己也带了一份 Git,里面没有带 GPG,所以使用了 Gpg4Win 的 GPG,于是就有 GUI 提示了。
    第 2 条附言  ·  2017-08-26 11:55:10 +08:00
    再说一下,实际测试发现直接执行 git config --global gpg.program gpg2 也是可以的。
    5 条回复    2017-08-25 19:43:47 +08:00
    ysc3839
        1
    ysc3839  
    OP
       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
        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 提示了。
    jsw
        3
    jsw  
       2017-08-25 19:30:50 +08:00
    原文引用:
    ```
    jsw
        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.
    ```
    ysc3839
        5
    ysc3839  
    OP
       2017-08-25 19:43:47 +08:00
    @jsw 用 Process Explorer 看了一下,Git 确实使用了自带的 GPG。
    VS 自己也带了一份 Git,里面没有带 GPG,所以使用了 Gpg4Win 的 GPG,于是就有 GUI 提示了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1368 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:35 · PVG 07:35 · LAX 16:35 · JFK 19:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.