Git无法签署提交

q9rjltbz  于 2023-05-12  发布在  Git
关注(0)|答案(2)|浏览(157)

我按照Github上的说明设置了Git签名,但是当我尝试签名和提交时,我得到了以下错误。我在网上搜索了一下,但我不知道为什么--help被包含在签名命令中。我使用的是Mac(M2),Git版本是2.40.1

╭─rishabh@WKW305277K ~/Development/src  ‹feature/list-by-currency*›
╰─➤  GIT_TRACE=1 git commit -m "Initial commit"

13:02:32.970213 git.c:439               trace: built-in: git commit -m 'Initial commit'
13:02:32.991133 run-command.c:655       trace: run_command: --help --status-fd=2 -bsau 6C3C23C559AA013D352F8790061E0F7BCE5EABB8
error: cannot run --help: No such file or directory
error: gpg failed to sign the data:
(no gpg output)
fatal: failed to write commit object

为了帮助调试问题,以下是所需的信息:

  1. ~/.gitconfig的含量
╭─rishabh@WKW305277K ~
╰─➤  cat ~/.gitconfig

[filter "lfs"]
    required = true
    clean = git-lfs clean -- %f
    smudge = git-lfs smudge -- %f
    process = git-lfs filter-process
[user]
    name = Rishabh
    email = rishabh@example.com
    signingkey = 6C3C23C559AA013D352F8790061E0F7BCE5EABB8
[init]
    defaultBranch = master
[pull]
    rebase = false
[commit]
    template = /Users/rishabh/.gitmessage
    gpgsign = true
[core]
    excludesfile = /Users/rishabh/.gitignore_global
[difftool "sourcetree"]
    cmd = opendiff \"$LOCAL\" \"$REMOTE\"
    path =
[mergetool "sourcetree"]
    cmd = /Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
    trustExitCode = true
[gpg]
    program = /opt/homebrew/opt/gnupg@2.2/bin/gpg
  1. gpg --status-fd=2 -bsau <key>的输出
╭─rishabh@WKW305277K ~
╰─➤  gpg --status-fd=2 -bsau 6C3C23C559AA013D352F8790061E0F7BCE5EABB8

[GNUPG:] KEY_CONSIDERED 6C3C23C559AA013D352F8790061E0F7BCE5EABB8 2
[GNUPG:] BEGIN_SIGNING H8
^C
gpg: signal Interrupt caught ... exiting
dced5bon

dced5bon1#

该解决方案要求我检查各个存储库上git config --global gpg.programgit config gpg.program的输出,然后我注意到在各个存储库上有以下内容:

╭─rishabh@WKW305277K ~/Development/src  ‹feature/list-by-currency*›
╰─➤  git config gpg.program
--help

我通过将值设置为下面的值来纠正它,它纠正了我的问题。

git config gpg.program gpg
7cjasjjr

7cjasjjr2#

使用此命令调试问题:

gpg --status-fd=2 -bsau <your GPG key>

这可能是因为gpg密钥已过期或gpg密钥未正确设置。
根据此答案,您可以更新它:

git config --global gpg.program gpg1

或者您可以通过列出密钥来设置它,然后为用户添加密钥:

gpg --list-secret-keys --keyid-format=long
git config --global user.signingkey <your key>

相关问题