【问题标题】:Git commit gets permission denied but works with --no-verifyGit 提交被拒绝,但与 --no-verify 一起使用
【发布时间】:2020-08-19 21:01:22
【问题描述】:

当我运行时,git commit -m 'Test' 收到此消息:

[INFO] Initializing environment for git@github.com:humitos/mirrors-autoflake.git.
An unexpected error has occurred: CalledProcessError: command: ('/usr/local/git/libexec/git-core/git', 'fetch', 'origin', '--tags')
return code: 128
expected return code: 0
stdout: (none)
stderr:
    git@github.com: Permission denied (publickey).
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.

Check the log at /Users/amit/.cache/pre-commit/pre-commit.log

但如果运行git commit -m 'Test' --no-verify,它工作正常。我的预提交钩子有问题,有什么想法吗?

【问题讨论】:

  • 您的 pre-commit 挂钩尝试运行 git fetch origin --tags 并未能通过身份验证。可以手动运行命令吗?
  • 感谢@phd,是的,我尝试手动运行它,它工作正常,拉新分支没有任何问题。
  • 我的下一个想法更复杂——pre-commit 钩子使用sudo 在不同的用户下运行命令,从而失去对 SSH 密钥的访问权限。但是如果不查看钩子的代码,就很难调试。
  • 你是对的@phd!我修复了一些文件权限,虽然现在得到了这个,An error has occurred: InvalidManifestError: =====> /Users/amit/.cache/pre-commit/repo29erukkj/.pre-commit-hooks.yaml does not exist Check the log at /Users/amit/.cache/pre-commit/pre-commit.log

标签: git pre-commit pre-commit.com


【解决方案1】:

您的 .pre-commit-config.yaml 文件似乎使用 ssh url 引用了一个 git 存储库,但您没有配置 github 的 ssh 密钥

您可以安全地将对repo: git@github.com:humitos/mirrors-autoflake 的引用替换为repo: https://github.com/humitos/mirrors-autoflake(尤其是因为这是一个公共存储库)

【讨论】:

    【解决方案2】:

    我能够通过从 .gitconfig

    中删除以下行来修复它
    [url "git@github.com:"]
            insteadOf = https://github.com/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-19
      • 1970-01-01
      • 2020-01-25
      • 2018-02-14
      • 1970-01-01
      • 2021-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多