git Android Studio - 推送失败:致命:无法从远程存储库读取

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24688700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:17:24  来源:igfitidea点击:

Android Studio - Push failed: fatal: Could not read from remote repository

gitintellij-ideaandroid-studiobitbucket

提问by mFeinstein

I have a git project at Android Studio and a remote at BitBucket and I changed it to use SSH instead of HTTPS. I can make everything work using Atlassian's SourceTree, but in Android Studio every time I try to push the project it says

我在 Android Studio 有一个 git 项目,在 BitBucket 有一个远程项目,我将其更改为使用 SSH 而不是 HTTPS。我可以使用 Atlassian 的 SourceTree 使一切正常,但在 Android Studio 中,每次我尝试推送项目时,它都会说

Push failed: fatal: Could not read from remote repository.

推送失败:致命:无法从远程存储库读取。

Does anyone have a clue about what could be happening?

有没有人知道会发生什么?

回答by Nicolas Zozol

This is probably an Intellij problem. Your key are managed natively by ssh, and Intellij has it's own ssh program.

这可能是一个 Intellij 问题。您的密钥由 ssh 本地管理,并且 Intellij 拥有自己的 ssh 程序。

Go to the settings, search git->ssh executable then choose native

转到设置,搜索 git->ssh 可执行文件,然后选择 native

As seen here : git with IntelliJ IDEA: Could not read from remote repository

如下所示:带有 IntelliJ IDEA 的 git:无法从远程存储库读取

回答by Joe Wang

There is two ways for Git SSH verification in Android Studio or IntelliJ, changing via: settings - Version Control - Git - SSH excuteable - "Built-in" or "Native"

在 Android Studio 或 IntelliJ 中 Git SSH 验证有两种方式,通过以下方式更改:设置 - 版本控制 - Git - SSH 可执行 - “内置”或“本机”

  1. Built-in : means using ssh key pair built in Git for authentication. you can generate it via
    ssh-keygen -t rsa
    the default saved path is "~/.ssh/id_rsa"and "~/.ssh/id_rsa.pub". You should add the Public key in your BitBucket account. the path like : manage account - SSH keys - add keys
  2. Native : means using the ssh pair generated by the native repository hosting service, such as BitBucket or GitHub, which is often auto-add in the service account. For example in GitHub. It generated a pair of SSH key, "~/.ssh/github_rsa.pub" and "~/.ssh/github_rsa" and the Public key has been auto-added in my account via GitHub GUI maybe. So change the SSH executable to "Native" could be a simple way.
  1. 内置:表示使用 Git 内置的 ssh 密钥对进行身份验证。您可以通过
    ssh-keygen -t rsa
    默认保存路径生成它,即"~/.ssh/id_rsa""~/.ssh/id_rsa.pub"。您应该在您的 BitBucket 帐户中添加公钥。路径如:管理帐户 - SSH 密钥 - 添加密钥
  2. Native : 表示使用本地存储库托管服务生成的 ssh 对,例如 BitBucket 或 GitHub,通常会自动添加到服务帐户中。例如在 GitHub 中。它生成了一对 SSH 密钥,“~/.ssh/github_rsa.pub”和“~/.ssh/github_rsa”,并且公钥可能已通过 GitHub GUI 自动添加到我的帐户中。因此,将 SSH 可执行文件更改为“本机”可能是一种简单的方法。

Anyway, you can use the both way after you add the correct Public key in you acoount in repository hosting service.

无论如何,您可以在存储库托管服务的帐户中添加正确的公钥后使用这两种方式。

回答by Johnny

Go to Settings > Version Control > Git. Make sure SSH executable is set to “Native.”

转到设置 > 版本控制 > Git。确保 SSH 可执行文件设置为“本机”。

If it's already set, switch back to “Built-in,” apply it, and then again switch back to “Native".

如果已设置,请切换回“内置”,应用它,然后再次切换回“本机”。

enter image description here

在此处输入图片说明

回答by Roman Nazarevych

Despite my SSH-executable was set to NativeI was getting that error because I have set password for SSH key file.

尽管我的 SSH-executable 设置为Native我收到该错误,因为我已经为 SSH 密钥文件设置了密码。

I haven't found the way how to specify password in Android studio but there is another solution, you can remove password which can be done with $ ssh-keygen -p. Then just confirm file location, enter your old password and leave new password blank.

我还没有找到如何在 Android Studio 中指定密码的方法,但还有另一种解决方案,您可以使用$ ssh-keygen -p. 然后只需确认文件位置,输入您的旧密码并将新密码留空。

Taken from How do I remove the passphrase for the SSH key without having to create a new key?

摘自如何在无需创建新密钥的情况下删除 SSH 密钥的密码?

回答by mdzeko

I got the same issue. Turns out it matters how you run Android Studio. If you run it with normal privileges from terminal or sth, it cannot read local files that it has to in order to push repository.

我遇到了同样的问题。事实证明,如何运行 Android Studio 很重要。如果您从终端或 sth 以普通权限运行它,它无法读取本地文件,以便推送存储库。

Solutionmight just be to restart Android Studio with more privileges than it currently has.

解决方案可能只是使用比当前更多的权限重新启动 Android Studio。

回答by taimoorAshfaq

Go to github.com and open your repository and copy USE HTTPS url Go to your Android project directory. In the .git folder search for config file.

转到 github.com 并打开您的存储库并复制 USE HTTPS url 转到您的 Android 项目目录。在 .git 文件夹中搜索配置文件。

IN the config file change url which you copied from github.com (use https) with the previous url. save config file and push again. This worked for me.

在配置文件中更改您从 github.com(使用 https)复制的 url 和之前的 url。保存配置文件并再次推送。这对我有用。

回答by Alexander Poleschuk

I had a similar problem in Android Studio 3.1

我在 Android Studio 3.1 中遇到了类似的问题

I changed Preferences > Version Control > Git > SSH executablefrom Built-into Nativeas suggested here but it didn't help.

我按照此处的建议将首选项 > 版本控制 > Git > SSH 可执行文件内置更改为本,但没有帮助。

Then I upgraded Android Studio to 3.2 and switched back to Built-in. It fixed the issue in my case.

然后我将 Android Studio 升级到 3.2 并切换回Built-in。它解决了我的问题。

回答by EXEEE

I have met this problem, and finally I have solved it. And there are two important points for setting: In the android studio: File-Settings-GitHub: not to choose "Clone git repositories using ssh" In the android studio: File-Settings-Git: Choose "Built-in" for "SSH executable"

我遇到过这个问题,终于解决了。并且有两个重要的设置点: 在android studio中:File-Settings-GitHub:不要选择“Clone git repositories using ssh” 在android studio中:File-Settings-Git:为“SSH”选择“Built-in”可执行”

and for the SSH that I already have in the account of GitHub, is the one that I have in the android studio, I forget how to find the SSH in the android studio, But you can find it by the other way

而对于我在GitHub的账户中已有的SSH,是我在android studio中的那个,我忘记了如何在android studio中找到SSH,但是你可以通过其他方式找到

回答by Clay H

I ran across this myself, and found the existing answers were a bit incomplete.

我自己遇到了这个问题,发现现有的答案有点不完整。

tl;dr: Switching Android Studio/IntelliJ's SSH client from built-in to native may resolve the issue for you (it did for me).

tl; dr:将 Android Studio/IntelliJ 的 SSH 客户端从内置切换到本机可能会为您解决问题(对我来说确实如此)。

Android Studio (effectively a specialized IntelliJ IDEA) comes with its own built-in SSH client, but allows you to switch to native (platform / OS dependent) if you prefer. You can change this by opening your Android Studio options, search for 'git', and choose 'native' in the SSH executable dropdown.

Android Studio(实际上是一个专门的 IntelliJ IDEA)带有自己的内置 SSH 客户端,但如果您愿意,它允许您切换到本机(平台/操作系统相关)。您可以通过打开 Android Studio 选项,搜索“git”并在 SSH 可执行文件下拉列表中选择“native”来更改此设置。

In my case, I was unable to push to BitBucket through Android Studio, but git pushworked just fine. Switching to native (OSX SSH, in my case) resolved the issue - now I can push to BitBucket from Android Studio.

就我而言,我无法通过 Android Studio 推送到 BitBucket,但git push工作得很好。切换到本机(在我的情况下为 OSX SSH)解决了该问题 - 现在我可以从 Android Studio 推送到 BitBucket。

Other answers touched on the subject, but there appears to have been some mixup between SSH executables and the keys that they use.

其他答案涉及该主题,但 SSH 可执行文件和它们使用的密钥之间似乎存在一些混淆。

Per Android Studio help under SSH Executable:

根据 SSH Executable 下的 Android Studio 帮助:

  • Built-in: select this option to use the implementation provided by IntelliJ IDEA.
  • Native: select this option to use native implementation.
  • 内置:选择此选项以使用 IntelliJ IDEA 提供的实现。
  • 本机:选择此选项以使用本机实现。

回答by Atul Bahuguna

If changing Preferences > Version Control > Git > SSH executable from Built-into Nativeis not working then pls try with unchecking the Preferences > Version Control > GitHub>clone git repositories using sshCHECK IT

如果改变首选项>版本控制>的Git>从内置SSH可执行文件本机不工作然后请与取消选中尝试首选项>版本控制>的GitHub>克隆Git仓库使用ssh检查