根据this link,我只需要使用我的GPG密钥包含-S
开关来签署我的提交,但我不知道如何在Android Studio中使用它。
如何在Android Studio中签署我的提交?
编辑:我很欣赏OSX解决方案的出现,但我真的希望看到一个适用于Windows的答案。我只使用我的Mac作为文档和东西。
进行一些测试后我按照这个步骤进行操作请按照以下步骤重新启动Android Studio:
你是否厌倦了为每次提交写密码?
nano~ / .gnupg / gpg.conf
use-agent
no-tty
default-key <your key id>
ln -s /usr/local/Cellar/libgcrypt/1.7.0_1 / usr / local / opt / libgcrypt
ln -s /usr/local/Cellar/libgpg-error/1.22 / usr / local / opt / libgpg-error
ln -s /usr/local/Cellar/libassuan/2.4.2 / usr / local / opt / libassuan
ln -s /usr/local/Cellar/pth/2.0.7 / usr / local / opt / pth
来源〜/ .profile
git commit -am“我的提交消息”-S
而已!!!
正如我在“Sign git commits with GPG”中提到的,使用Git 2.0:
如果要对所有提交进行GPG签名,则必须始终添加-S选项。
commit.gpgsign
配置选项允许自动签署所有提交。
这不完全有效,并且是followed by issue 127802,具有以下变通方法:
使用该内容创建了一个帮助脚本:
/usr/bin/gpg –batch –no-tty "$@"
并将
gpg.program
设置为该脚本
要么:
将“
no-tty
”添加到“~/.gnupg/gpg.conf
”为我解决了这个问题。
您可能仍会收到错误消息:
Commit failed with error:
gpg: problem with the agent - disabling agent use
gpg: Sorry, no terminal at all requested - can't get input
error: gpg failed to sign the data
fatal: failed to write commit object
再次:bug正在进行中,其次是issue 110261:
除了之前的解决方案(OS X)之外,还要解决此问题:
1)
brew install gnupg gnupg2 pinentry-mac
2)
nano ~/.gnupg/gpg-agent.conf
- >pinentry-program /usr/local/bin/pinentry-mac
3)
git config -–global gpg.program gpg2
如果您安装了适用于Windows的git,并在安装过程中选择了MingGW选项,那么这就是我使用Android Studio处理签名提交的过程。
提供/使用的程序,用于那些尚未拥有它们的人。
对于那些想要阅读文章的人,我曾经在我的Windows环境中使用gpg签名工作(从git config
行开始的页面的下半部分是我们更关心的):https://jamesmckay.net/2016/02/signing-git-commits-with-gpg-on-windows/
我将简要介绍一下通过命令行执行gpg部分的过程 - 假设所有三个程序都是从这里开始安装的。
如果您尚未在Android Studio中指定git的位置,请在“设置”中执行以下操作:
注意:这可以在一个项目的
File > Project Settings
或File > Other Settings > Default Settings...
中完成版本控制> Git> Git可执行文件的路径
由于我使用的是MinGW版本,因此设置为:C:\Program Files\Git\mingw64\bin\git.exe
注意:使用MinGW提示程序执行
gpg --export > ~/gpg-public
gpg --export-secret-keys > ~/gpg-secret
注意:对于那些不知道的人,~/
默认设置为用户的主目录。 (例如Windows 10:C:/Users/%USERNAME%
)
注意:使用Windows命令提示符执行。
gpg --import < "C:/Users/%USERNAME%/gpg-public"
gpg --import < "C:/Users/%USERNAME%/gpg-secret"
将地址替换为gpg-public
和gpg-secret
文件的位置。
正如文章中提到的那样。如果你没有打开它,它会在这里重新发布。
注意:使用MinGW提示程序执行
git config --global gpg.program "C:/Program Files (x86)/GNU/GnuPG/gpg2.exe"
将gpg.program
值(保持gpg2.exe
)替换为您指定gpg4win安装程序以安装它的位置。
(可选)当您使用它时,您可以配置您的git以使用默认密钥自动签署您的提交(需要git version> = 2.0)
git config --global user.name <name>
git config --global user.email <email>
git config --global user.signingkey <your-key-ID>
git config --global commit.gpgsign true
用您自己的值替换< >
中的值。您可以通过运行gpg --list-keys
并从pub
开始并在/
之后的行中获取ID来获取密钥ID。
现在您应该能够使用Android Studio提交并看到密码输入的提示。