Git signed commits - How to suppress “You need a passphrase to unlock the secret key…”

佐手、 提交于 2019-12-18 11:52:06

问题


I changed my global Git configuration to sign all commits. I also use gpg-agent so that I don't have to type my password every time.

Now every time I make a new commit I see the following five lines printed to my console:

[blank line]
You need a passphrase to unlock the secret key for
user: "John Doe <mail@gmail.com>"
2048-bit RSA key, ID ABCDEF12, created 2016-01-01
[blank line]

Even worse, when I do a simple stash, this message is printed twice, needlessly filling my console (I assume for one for each of the two commit objects that are created).

Is there a way to suppress this output?


回答1:


This is more a gpg configuration issue than a git one.

Since you are using an agent, you could as a workaround add no-tty to your gpg.conf.

echo 'no-tty' >> ~/.gnupg/gpg.conf

(this seems working even better than the --batch option)




回答2:


The accepted answer doesn't work for me for Git version 1.8.3.1 on Fedora 25.

What worked ?

  1. Check if gpg-agent is running by
    $ gpg-agent

  2. Make sure gpg-agent has your passphrase in cache. To make sure it is there, sign any file in the current directory. If the passphrase was not in the cache, it will be asked now.
    $ gpg -s any-file.txt

  3. Don't forget to delete the newly generated signed any-file.txt.gpg
    $ rm any-file.txt.gpg

  4. Now, signing commits with Git will work now by taking the required passphrase from gpg-agent.
    $ git commit -S -m 'my commit message'



来源:https://stackoverflow.com/questions/37763170/git-signed-commits-how-to-suppress-you-need-a-passphrase-to-unlock-the-secret

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!