【发布时间】:2020-12-28 18:22:32
【问题描述】:
我的 Flutter 应用依赖于一个私有托管在 github 上的模块。
当我从 Powershell 运行 pub get 时,我得到:
Git error. Command: `git clone --mirror ssh://git@github.com:dirkbo/repo-name.git C:\src\flutter\.pub-cache\git\cache\repo-name-123ba`
stdout:
stderr: Cloning into bare repository 'C:\src\flutter\.pub-cache\git\cache\repo-name-123ba'...
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.
exit code: 128
当我复制失败的命令并直接在同一个 powershell 中运行时:
git clone --mirror git@github.com:dirkbo/repo-name.git C:\src\flutter\.pub-cache\git\cache\repo-name-123ba
一切正常:
Cloning into bare repository 'C:\src\flutter\.pub-cache\git\cache\repo-name-123ba'...
Enter passphrase for key '/c/Users/dirkb/.ssh/id_rsa':
remote: Enumerating objects: 229, done.
remote: Counting objects: 100% (229/229), done.
remote: Compressing objects: 100% (132/132), done.
remote: Total 229 (delta 13), reused 229 (delta 13), pack-reused 0
Receiving objects: 100% (229/229), 19.32 MiB | 1.45 MiB/s, done.
Resolving deltas: 100% (13/13), done.
在我的pubspec.yaml 我试过了:
repo:
git: ssh://git@github.com/dirkbo/repo-name.git
(结果见上)
和
repo:
git: git@github.com:dirkbo/repo-name.git
这给了我:
Git error. Command: `git fetch`
stdout:
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.
exit code: 128
运行pub get 的批处理命令似乎找不到我的 ssh 密钥。
【问题讨论】:
-
您可以尝试通过 pubspec 指定分支和依赖项名称吗?喜欢:
dependencies: kittens: git: url: git@github.com:munificent/kittens.git ref: some-branch你也可以试试ssh://git@github.com:munificent/kittens(删除.git) -
我已经尝试了你的两个建议,结果是一样的。似乎 pub get 在不同的 shell 中运行,我的 ssh-key 是未知的。
-
您是在 Visual Studio Code 还是在 android Studio 中运行您的应用程序?还是别的什么?
-
我在 AndroidStudio 和 Windows Powershell 中尝试过。
-
这可能与路径问题有关? Powershell 使用 home 目录作为默认位置,而 AndroidStudio 来自项目文件夹。这可能会导致混淆,具体取决于您的 SSH 客户端和操作系统。我假设你在 Windows 上,对吧?