如何通过 Windows 上的 ssh 阻止 git 解决错误的路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1092583/
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
How to stop git via ssh on windows from resolving the wrong path?
提问by Dane O'Connor
I have a windows 2003 box with an ssh server setup. I have msysgit (git version 1.6.2) installed both locally and on the server.
我有一个带有 ssh 服务器设置的 Windows 2003 盒子。我在本地和服务器上都安装了 msysgit(git 版本 1.6.2)。
The server has the following absolute path to my repos:
服务器对我的存储库具有以下绝对路径:
e:\vc\git\myrepo.git
when a user logs in he/she will be put in the following working directory:
当用户登录时,他/她将被放置在以下工作目录中:
e:\vc\git\
When running the following cmd on my dev machine:
在我的开发机器上运行以下 cmd 时:
git clone ssh://myuser@myip/myrepo.git testrepo
I get the following error:
我收到以下错误:
fatal: ''/myrepo.git'' does not appear to be a git repository
According to my ssh logs it appears that git is executing this cmd on the server:
根据我的 ssh 日志,git 似乎正在服务器上执行此 cmd:
'cmd.exe /c git-upload-pack '/myrepo.git''
Executing that command locally (on the server) fails for the same reason. I'm thinking the problem is related to git prefixing the path with a '/'. How do I tell git not to do this? Should this be working?
由于同样的原因,在本地(在服务器上)执行该命令失败。我认为问题与 git 在路径前加上“/”有关。我如何告诉 git 不要这样做?这应该有效吗?
Note: git-upload-pack is working because I added \gitinstallpath\libexec\git-core to the path. Apparently this is a bug and will be fixed in the future, this was my work around.
注意: git-upload-pack 正在工作,因为我将 \gitinstallpath\libexec\git-core 添加到路径中。显然这是一个错误,将来会修复,这是我的工作。
回答by Dane O'Connor
I resolved this by switching my ssh server from winssh to openssh (via the cygwin layer). I was able to connect fine (as noted above) using winsshd, but winsshd wasn't correctly handling paths prefixed with "/". I could probably get winsshd to work, but switching to cygwin and openssh was faster.
我通过将我的 ssh 服务器从 winssh 切换到 openssh(通过 cygwin 层)解决了这个问题。我能够使用 winsshd 正常连接(如上所述),但是 winsshd 没有正确处理以“/”为前缀的路径。我可能可以让 winsshd 工作,但切换到 cygwin 和 openssh 会更快。
Here's a good blog postto kick start the setup if your in a similar situation:
如果您处于类似情况,这里有一篇很好的博客文章可以启动设置:
回答by Tim Henigan
Have you tried the following?
您是否尝试过以下方法?
git clone ssh://myuser@myip/myrepo testrepo
Note the removal of ".git" from the end of the SSH path. You only need that suffix at the end if the remote directory name has it.
请注意从 SSH 路径的末尾删除了“.git”。如果远程目录名称具有该后缀,则您只需要该后缀。
Also, have you tried any other SSH URL format? To use a relative path, you can try:
另外,您是否尝试过任何其他 SSH URL 格式?要使用相对路径,您可以尝试:
git clone ssh://myuser@myip/~/myrepo testrepo
See the git clone man pagefor details on other URL formats.
有关其他 URL 格式的详细信息,请参阅git clone 手册页。
回答by Konstantin
If somebody still interested in workaround:
如果有人仍然对解决方法感兴趣:
The problem is - cmd.exe doesn't understand single-quoted parameters. So we use sh instead.
问题是 - cmd.exe 不理解单引号参数。所以我们改用 sh 。
Create file gup.sh with line
用行创建文件 gup.sh
git-upload-pack.exe $*
and grp.sh with
和 grp.sh 与
git-receive-pack.exe $*
on server!
在服务器上!
Then run:
然后运行:
git clone -u 'sh gup.sh' ssh://myuser@myip/e/vc/git/myrepo.git testrepo git config remote.origin.uploadpack 'sh gup.sh' git config remote.origin.receivepack 'sh grp.sh'