git - 某些 git 路径的权限被拒绝

标签 git git-submodules gerrit permission-denied

我需要从 gerrit 服务器克隆一个子模块到我的本地项目。这是一个有效的 .gitmodule 文件:

[submodule "blah/blah/thing"]
  path = blah/blah/thing
  url = ssh://my_username@gerrit.somewhere.com/some-thing.git

这是一个我想使用的 .gitmodule 文件,因为它适用于其他团队成员:

[submodule "blah/blah/thing"]
  path = blah/blah/thing
  url = gerrit.somewhere.com:some-thing.git

当我尝试使用后一种形式时,出现此错误:

$ git submodule update --init --recursive
Submodule 'blah/blah/thing' (gerrit.somewhere.com:some-thing.git) registered for path 'blah/blah/thing'

Cloning into 'blah/blah/thing'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Clone of 'gerrit.somewhere.com:some-thing.git' into submodule path 'blah/blah/thing' failed

怎么了?

最佳答案

不要将您的用户名放在.gitmodule 文件中。这将导致所有用户尝试使用您的用户名获取子模块。而是遵循第二个示例中的格式,并在 .ssh/config 文件中指定您的用户名:

Host gerrit.somewhere.com
    User my_username

(假设您使用的是 ssh,情况似乎是这样。如果您还使用 https,请查看 .netrc 文件)。

关于git - 某些 git 路径的权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17032637/

相关文章:

git - 如何在 Windows 中克隆包含 Windows 文件系统无效符号的存储库

python - 如何从git子模块导入python文件

git - Makefile中子模块的自动初始化和更新

android-studio - Android Studio 中是否可以看到 Gerrit 插件的注释?

git - 无法安装 Gerrit 的 commit-msg 钩子(Hook);身份验证似乎很好

eclipse - 如何在没有历史记录的系统上从分支 A 挑选到分支 B?

vb.net - Git编译错误

git - 如何使docker-compose将上下文从GIT加载到特定目录?

Git 不识别任何远程分支

git - 添加 Git 子模块时如何指定分支/标签?