You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git提交签名失败:命令含--help致执行错误求助

Git提交签名报错:无法运行--help的解决方案

问题详情

按照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

2. 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

解决方案

从错误日志能看出,Git错误地将--help当成了签名程序执行,核心问题是gpg程序的配置未被正确识别,按以下步骤排查修复:

  1. 验证gpg路径有效性
    运行命令检查配置的gpg路径是否存在:

    ls /opt/homebrew/opt/gnupg@2.2/bin/gpg
    

    如果返回“文件不存在”,说明brew安装的gnupg版本或路径不符,用which gpg获取正确路径,然后更新~/.gitconfig中的gpg.program值,示例:

    [gpg]
        program = /usr/local/bin/gpg
    
  2. 检查环境变量覆盖
    运行命令查看是否有环境变量覆盖了gpg程序配置:

    echo $GIT_GPG_PROGRAM
    

    如果输出是--help,需要清空这个环境变量:

    unset GIT_GPG_PROGRAM
    

    若要永久生效,需从~/.zshrc或~/.bashrc中删除相关设置。

  3. 确认Git配置加载正确
    运行命令查看全局gpg程序配置:

    git config --get gpg.program
    

    再检查当前仓库的本地配置是否覆盖了全局设置:

    git config --local --get gpg.program
    

    如果本地配置有错误值,用以下命令清除:

    git config --local --unset gpg.program
    
  4. 测试Git调用gpg
    完成上述调整后,重新执行提交命令,或用以下命令直接测试Git的gpg调用:

    echo "test" | git gpg --sign
    

内容的提问来源于stack exchange,提问作者Rishabh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 22:22:43