How to stop git via ssh on windows from resolving the wrong path?

爷,独闯天下 提交于 2019-11-27 06:16:00

问题


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.

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:

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:

'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?

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.


回答1:


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.

Here's a good blog post to kick start the setup if your in a similar situation:




回答2:


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.

Also, have you tried any other SSH URL format? To use a relative path, you can try:

git clone ssh://myuser@myip/~/myrepo testrepo

See the git clone man page for details on other URL formats.




回答3:


If somebody still interested in workaround:

The problem is - cmd.exe doesn't understand single-quoted parameters. So we use sh instead.

Create file gup.sh with line

    git-upload-pack.exe $*  

and grp.sh with

    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'  


来源:https://stackoverflow.com/questions/1092583/how-to-stop-git-via-ssh-on-windows-from-resolving-the-wrong-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!