我正在努力在 Windows 服务器(2019)上设置 git 存储库,尝试遵循 https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server 。但是,无论我做什么,git push 都会出现 fatal: ''/Users/testing/testrepo.git'' 似乎不是 git 存储库。
我跑了:
git 初始化
git add test.txt(测试文件,仅包含测试)
git commit -m“测试”
git远程添加源测试@(已删除):Users/testing/testrepo.git
git push origin master
在为此苦苦挣扎了一段时间后,我启用了 ssh 日志记录,并在服务器端日志文件中找到了这一行:
7744 2021-06-09 03:58:37.691 debug1:执行命令:“c:\windows\system32\cmd.exe”/c“git-receive-pack'/Users/testing/testrepo.git'”没有pty
我尝试手动运行 git-recieve-pack '/Users/testing/testrepo.git',但出现了相同的错误。但是,我随后尝试运行 git-receive-pack "/Users/testing/testrepo.git",它给出了
00bb0000000000000000000000000000000000000000 功能^{} report-status report-status-v2 delete-refs side-band-64k安静原子 ofs-delta 对象格式=sha1 代理=git/2.32.0.windows.1
0000
唯一的区别是“而不是'。这对Windows服务器来说是奇怪的事情,还是我做错了什么?
最佳答案
事实证明这是我使用的 ssh 服务器的问题:https://github.com/PowerShell/Win32-OpenSSH/issues/752 。评论中的解决方法之一是将 git receivepack 和 uploadpack 命令设置为使用 powershell,但由于我不想为我的全局 git 配置更改它,或者必须为每个存储库执行此操作,所以我找到了更好的解决方案。正在关注https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_server_configuration ,我在 HKLM:\SOFTWARE\OpenSSH 中添加了一个 key :DefaultShell = "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe"。现在,ssh 命令默认情况下会转到该服务器上的 powershell,这解决了 git-receive-pack 的问题。
关于git-receive-pack 使用双引号,但不使用单引号,而 git 使用单引号调用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67903167/