GIT远程无法通过SSH获取

标签 git ssh repository fetch

我刚刚在现有网站根目录中初始化了一个 GIT 存储库。 我有这个网站的本地开发副本,它已经是一个 GIT 存储库。我不能只是从另一个克隆一个,因为多年来本地/实时版本已经不同步。

我正在尝试让它们再次与 GIT 对齐,但我希望能够在实时站点上执行 fetch 操作并运行 git diff

我的问题是,在本地站点上,我已将实时站点添加为远程存储库:

git remote add live <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dda8aeb8af9daeb8afabb8aff3beb2f3a8b6" rel="noreferrer noopener nofollow">[email protected]</a>:/path/to/repo

我可以通过 ssh 成功登录到我的服务器:

ssh <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="95e0e6f0e7d5e6f0e7e3f0e7bbf6fabbe0fe" rel="noreferrer noopener nofollow">[email protected]</a>

但是当我尝试获取并输入 ssh 密码时,命令行仅返回密码提示,就好像我输入了错误一样。但我知道密码是正确的,因为我可以使用 SSH 登录。

我是否必须在远程 URL 之前指定 ssh://?我需要做些什么才能让 ssh 远程存储库正常工作

更新

我添加了 ssh:// 前缀,但没有什么区别。这就是它在 .git/config 中的样子

[remote "live"]
    url = ssh://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4e3b3d2b3c0e3d2b3c382b3c602d21603b25" rel="noreferrer noopener nofollow">[email protected]</a>/path/to/repo
    fetch = +refs/heads/*:refs/remotes/live/*

运行 GIT_TRACE=true git fetch live 添加以下行:

trace: run_command 'ssh' '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f4a4c5a4d7f4c5a4d495a4d115c50114a54" rel="noreferrer noopener nofollow">[email protected]</a>' 'git-upload-pack '\''/path/to/repo'\'''

我必须输入密码 3 次才能收到消息:

fatal: the remote end hung up unexpectedly

最佳答案

我认为您缺少 Remote 的别名。

git remote add origin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="89fcfaecfbc9faecfbffecfba7eae6a7fce2" rel="noreferrer noopener nofollow">[email protected]</a>:/path/to/repo

注意origin一点。

您发布的 .git/config 准确吗?如果是,请尝试更改远程 URL

url = ssh://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3144425443714254434754431f525e1f445a" rel="noreferrer noopener nofollow">[email protected]</a>/path/to/repo

url = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d6a3a5b3a496a5b3a4a0b3a4f8b5b9f8a3bd" rel="noreferrer noopener nofollow">[email protected]</a>:/path/to/repo

注意:将服务器名称与服务器路径分开。

关于GIT远程无法通过SSH获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10410456/

相关文章:

java - Jsch ssh 到 Raspberry Pi 不执行任何操作

git - origin/, remotes/origin/Git 困惑

Git merge 命令

git - 基于微服务的应用程序发布自动化

git - 如何在与 JGit merge 之前发生冲突?

git - 从 git 历史记录中删除的文件仍然存在?

windows - docker 无法在 Windows 错误上运行

SSH-X "Warning: untrusted X11 forwarding setup failed: xauth key data not generated"

python - 在requirements.txt中包含python版本吗?

c# - 来自 ASP.NET MVC 后端的 Javascript 客户端延迟加载模型