【问题标题】:git push fatal failedgit push 致命失败
【发布时间】:2011-04-26 05:46:51
【问题描述】:

我不知何故删除了我的代码分支的整个目录。我克隆了一个新的。除了推,它工作得很好。

~/workspace/wtf (mybranch)]$ git push origin  mybranch 
error: Cannot access URL [my url], return code 22
fatal: git-http-push failed 

不过,git pull 可以。我该如何解决?

【问题讨论】:

  • 请阅读本手册here 并注意关于http.receivepack 的要点。

标签: git push


【解决方案1】:

我错误地使用 https 而不是 ssh 来获取新副本。 从那以后,我进行了修改和提交,但由于明显的原因无法推送。

为了恢复,我简单地将 .git/config 中的 [remote "origin"] 部分从

网址 = https://github.com/AIFDR/riab_core.git

url = git@github.com:AIFDR/riab_core.git

之后,我可以再推。

【讨论】:

  • 无需迁移到其他协议,如果您想通过 http 推送,请阅读我的回答。
  • 同意 Basil 的观点,在某些通过防火墙等访问受限的公司环境中,这是不必要的,也是不可能的。
  • ...问题出在git-http-push failed,我看到操作正在尝试通过 http 或 https 进行设置,-1。
【解决方案2】:

仅使用 git 实现更快的 HTTP 推送 - 不需要 webDAV

自 git 1.6.6 以来新的“smart-http”支持。新方法允许一次传输整个包,而不是作为单个文件。

您还可以使用 gitweb 在同一位置提供可浏览的 URL。

注意:由于访问是由 apache 控制的,因此您可以将任何 Auth 要求(htaccess 或 ldap 等)添加到每个存储库的设置中。

此答案假定您拥有远程服务器并希望添加/修复 http 支持。

第一: 检查 apache 日志,当 apache 尝试执行 git-http 支持的 cgi 脚本时,可能是权限被拒绝/无法定位错误。

为 git 添加 HTTP 支持

只需新建一个 git_support.conf 文件,并将其包含在 apache 中(在 httpd.conf 中添加 include 语句)

#
#  Basic setup for git-http-backend
#

SetEnv GIT_PROJECT_ROOT /opt/git_repos
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER  #IMportant !!! This could be your problem if missing

<Directory /opt/git>  # both http_backend and gitweb should be somewhere under here
        AllowOverride None
        Options +ExecCGI -Includes  #Important! Lets apache execute the script!
        Order allow,deny
        Allow from all
</Directory>

# This pattern matches git operations and passes them to http-backend
ScriptAliasMatch \
        "(?x)^/git/(.*/(HEAD | \
                        info/refs | \
                        objects/(info/[^/]+ | \
                                 [0-9a-f]{2}/[0-9a-f]{38} | \
                                 pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                        git-(upload|receive)-pack))$" \
        /opt/git/libexec/git-core/git-http-backend/$1

# Anything not matched above goes to displayable gitweb interface
ScriptAlias /git /opt/git/cgi-bin/gitweb.cgi/

结果是推/拉的能力:

me@machine /tmp/eddies $ git pull
Already up-to-date.

me@machine /tmp/eddies $ touch changedFile

me@machine /tmp/eddies $ git add .

me@machine /tmp/eddies $ git commit -am"commiting change"
[master ca7f6ed] commiting change
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 changedFile

me@machine /tmp/eddies $ git push origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 239 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
To http://mysecretdomain.com/git/eddies
   0f626a9..ca7f6ed  master -> master

您可以在线浏览这些更改..

来源: http://repo.or.cz/w/alt-git.git?a=blob_plain;f=gitweb/README

【讨论】:

  • 当我运行关于用户的重要行时,第 7 行,我得到 "SetEnv takes 1-2 arguments, an environment variable name and optional value to pass to CGI." -- 为什么?
  • 我猜这个值是空的,所以 setenv 只看到 0 个参数。因为 apache 使用重定向规则,所以 REMOTE_USER 可能为空,所以我们获取 REDIRECT_RMEOTE_USER。如果 RMEOTE_USER 已经定义(或者更确切地说是 REDIRECT 用户为空),您应该能够将分配设为可选。 httpd.apache.org/docs/2.0/mod/mod_setenvif.html#setenvif
【解决方案3】:

要通过 http 启用“git push”,您必须在网络服务器上启用 WebDAV。要为 Apache Webserver 执行此操作,只需编辑配置文件:

vim /etc/httpd/conf/httpd.conf

然后搜索以:开头的行

<Directory "/var/www/html">

在其后面添加以下行:

Dav On

确保您在 httpd.conf 中也有以下行未注释:

LoadModule dav_fs_module modules/mod_dav_fs.so

之后你就准备好了。使用以下命令重启 Apache Webserver:

service httpd restart

还要确保服务器上的所有 git 存储库文件都可由 pache:apache 用户和组使用:

chown -R apache:apache /var/www/html/your_git_repository

否则在执行“git push”时未能设置正确的权限将导致“PUT error: curl result=22, HTTP code=403”。

现在只需从您的客户端机器上执行“git push”,一切都应该可以工作了。

【讨论】:

  • 注意,如果用户克服了这个障碍,但在 apcahe 日志中看到关于 receive-pack stackoverflow.com/questions/792611/… 的错误
  • 这会起作用,但 DAV 不是 必需的,而且实际上执行起来比 smart-http 慢得多。
【解决方案4】:

您无法推送通过 HTTP 克隆的存储库。 您需要将 URL 更新为 ssh://git:// 类型的 URL。

【讨论】:

  • 我使用了相同的克隆命令。在我删除错误之前它一直有效....
  • 你对git remote -v有什么看法?
  • 不完全正确。假设 DAV 已启用,您可以推送回存储库。
  • 这是不正确的。从 1.6.6 开始的 Git 支持使用 apache 和 git-http-backend 进行智能 http 推送和拉取。
【解决方案5】:

编辑 .git/config 文件的以下部分:

[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://git.repository.url/repo.git

[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://username:password@git.repository.url/repo.git

那就试试git push origin master

根据需要在配置文件中编辑其他存储库 URL 的身份验证详细信息并推送到所需的分支。

【讨论】:

  • 注意:我使用了这种方法,它解决了我的问题 - 但是我认为将密码存储在配置文件中似乎是错误的,所以我将其关闭(希望得到提示),并且能够像这样使用它。
  • git remote set-url origin ... 也可以。
【解决方案6】:

我在使用 git-http-backend、ldap 身份验证配置进行推送操作时遇到了同样的问题。
最后我找到了解决方案并描述了它in this serverfault question

也许它会帮助有类似问题的人。

【讨论】:

    【解决方案7】:

    很棒

    我还有其他错误,但它有效!

    我试着解释一下:

    但是如何在推送消息的文本中隐藏密码?

    【讨论】:

      【解决方案8】:

      如果您输入了错误的密码,也会发生这种情况。

      【讨论】:

      • 我从未见过:我总是先得到fatal: Authentication failed
      猜你喜欢
      • 2012-08-15
      • 2021-08-02
      • 2014-07-20
      • 2021-03-15
      • 2013-03-21
      • 2014-04-30
      • 1970-01-01
      • 2022-01-21
      • 2023-03-04
      相关资源
      最近更新 更多