Skip to content

Instantly share code, notes, and snippets.

@snakevil
Created October 24, 2016 09:10
Show Gist options
  • Save snakevil/8aa4525db0a2726173a71c60cbb5130e to your computer and use it in GitHub Desktop.
Save snakevil/8aa4525db0a2726173a71c60cbb5130e to your computer and use it in GitHub Desktop.
使用 GnuPG2 为 Git 版本签名

使用 GnuPG2 为 Git 版本签名

从很久很久以前开始,我就一直用 GnuPG 对自己提交的 Git 代码签名。最初地时候是为了装X,后来则是为了确保代码的可靠性——毕竟 git config 都是随便写的。今天因为更换 Homebrew,顺路就更新到了 GnuPG2。但是,问题来了…

git commit -veS 报错:

You need a passphrase to unlock the secret key for
user: "Snakevil Zen <[email protected]>"
1024-bit RSA key, ID 37B86419, created 2015-02-02

gpg-agent[19813]: command get_passphrase failed: Inappropriate ioctl for device
gpg: problem with the agent: Inappropriate ioctl for device
gpg: skipped "37B86419": Operation cancelled
gpg: signing failed: Operation cancelled
error: gpg failed to sign the data
fatal: failed to write commit object

这是什么鬼?之前用 GnuPG 地时候可从来没有碰到过这种问题。

搜索,按照攻略添加一个环境变量搞定。

export GPG_TTY=$( tty )

因为我肯定用地是自己的 Bashrc.X 嘛(无耻打一波广告),所以实际上是添加了一个配置脚本 ~/.bashrc.x/bashrc.d/01-env.sh。无脑代码如下:

echo 'export GPG_TTY=$( tty )' >> ~/.bashrc.x/bashrc.d/01-env.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment