返回码 22,致命:git-http-push-failed
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21487164/
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
return code 22, fatal: git-http-push-failed
提问by Afilu
I made my own git repo on my server using git init --bare
. I added some files there and then cloned my repo from myserver by git clone http://www.example.com/mygit/repo
and it cloned perfectly. Now i want to push this directory by git push origin master
but it is returning code 22. I also added ssh public key of my PC to http://www.example.com/mygit/repo/.ssh/authorized_keys
but still i can't push into my repo.
我在我的服务器上使用git init --bare
. 我在那里添加了一些文件,然后从 myserver 克隆了我的 repo git clone http://www.example.com/mygit/repo
,它完美地克隆了。现在我想推送这个目录,git push origin master
但它返回代码 22。我还添加了我电脑的 ssh 公钥,http://www.example.com/mygit/repo/.ssh/authorized_keys
但我仍然无法推送到我的仓库中。
回答by Marcs
Try to add this to your config file in the bare repository:
尝试将其添加到裸存储库中的配置文件中:
[http]
receivepack = true
回答by Afilu
Just for the record, because this comes up high on google when searching "git-http-push failed return code 22":
只是为了记录,因为在搜索“git-http-push failed return code 22”时,这在谷歌上出现了高位:
With https git and htpasswd on the server, it seems that the user name sent includes the domain: [email protected]
, but the expected name is only user
.
在服务器上使用https git和htpasswd,发送的用户名似乎包含域:[email protected]
,但预期名称只有user
.
The solution for me was to add this in ~/.netrc
:
machine host.domain.tld
login the_user_name
password the_password
我的解决方案是将其添加到~/.netrc
:
machine host.domain.tld
login the_user_name
password the_password
回答by VonC
/repo/.ssh/authorized_keys
won't mean anything to your ssh daemon on your server: sshd will look for that file under the home of the user making the ssh query: /home/user/.ssh/authorized_key
/repo/.ssh/authorized_keys
对您服务器上的 ssh 守护程序没有任何意义:sshd 将在进行 ssh 查询的用户的主目录下查找该文件: /home/user/.ssh/authorized_key
Plus, if you are using https://... urls, you won't use ssh at all anyway. For an ssh url to work, you would need an Apache server properly configure to call the git-http-backend
script.
See for instance this git-http-backend question.
另外,如果您使用 https://... url,则无论如何您都不会使用 ssh。要使 ssh url 工作,您需要正确配置 Apache 服务器以调用git-http-backend
脚本。
参见例如这个git-http-backend question。
回答by learner_19
That is because you cloned using the http url and not the ssh url that is present on Github. And now you are trying to push using ssh which will not work. In such cases, git clone or git pull works but git push fails.
那是因为您使用 http url 而不是 Github 上存在的 ssh url 进行克隆。现在您正在尝试使用 ssh 进行推送,但这是行不通的。在这种情况下, git clone 或 git pull 工作但 git push 失败。
One solution is to clone using the ssh url which will be of the form [email protected]:username/repo-name.git You can find this url on ur Github repo when you click on SSH in "You can clone with HTTPS, SSH, or Subversion" message. And then make changes and do a git push. Make sure that the public key for your machine is present in your Github account.
一种解决方案是使用格式为 [email protected]:username/repo-name.git 的 ssh url 进行克隆,当您在“您可以使用 HTTPS 进行克隆, SSH 或 Subversion”消息。然后进行更改并执行 git push。确保您的机器的公钥存在于您的 Github 帐户中。
Another way for the current situation to work would be to supply username and password when doing a Git push.
当前情况的另一种工作方式是在执行 Git 推送时提供用户名和密码。