22

Another issue with git 1.8:

$ git push
error: dst ref refs/heads/master receives from more than one src.
error: failed to push some refs to 'gitosis@xxx.xx:xxx.git'

Suggestions? It was working before upgrading to 1.8.

$ git remote -v
origin  gitosis@xxx.xx:xxx.git (fetch)
origin  gitosis@xxx.xx:xxx.git (push)

After googling around I tried this first:

$ git push origin :refs/heads/refs/heads/master
remote: warning: Allowing deletion of corrupt ref.
To gitosis@xxx.xx:xxx.git
 - [deleted]         refs/heads/master

No idea what is that and why it was corrupt.

$ git pull
Already up-to-date.

$ git push
error: dst ref refs/heads/master receives from more than one src.
error: failed to push some refs to 'gitosis@xxx.xx:xxx.git'

Still not working, but origin master did work at least:

$ git push origin master
Counting objects: 42, done.
To gitosis@xxx.xx:xxx.git
3e3fc87..6e11d2a  master -> master

Okay, that kind of fixed it but what was the cause of the issue to begin with? Why origin/master suddenly got corrupted? What did I do with git push origin :refs/heads/refs/heads/master ?

.git/config:

[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = false
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = gitosis@xxx.xx:xx.git
push = HEAD
[branch "master"]
remote = origin
merge = refs/heads/master

ls .git/refs/remotes/origin:

HEAD    master  refs

In the end, now I have to do git push origin master every time. And the most annoying is that some repos work with git push, but on the most of them I got to add origin master but I don't understand why, and it can't be that I am alone having this problem.

4

5 回答 5

27

出现此错误的另一种方法是,如果您不小心输入了您尝试推送两次的分支的名称,即:

git push master otherBranch master moreBranches

产生此错误。一旦你意识到你已经完成了,修复就很明显了:

git push master otherBranch moreBranches
于 2016-06-19T19:20:06.337 回答
4

看起来您refsrefs/remotes/origin. 请注意refs/remotes/origin,您有一个额外的refs目录?我不知道这是如何到达那里的,但这可能是导致您的问题的原因。由于 Git 处理 refs 缩写的方式(允许您删除前缀,只使用后缀 like origin/master),它可能会因为同时拥有refs/remotes/origin/master和 而感到困惑refs/remotes/refs/remotes/origin/master

我不知道它是如何进入这种状态的;可能是 Git 工具中的错误,也可能是您在某个时候犯的错字。您通过删除跟踪此重复分支的远程分支解决了一半的问题。git push我敢打赌,如果您删除refs/remotes/origin/refs目录,您可以解决问题的另一半,并且能够再次这样做。

于 2012-11-16T11:26:35.233 回答
3

就我而言,我在分支名称中有一个空格:

git push origin 353-applyPermissions :353-applyPermissions

返回 > 错误:dst ref refs/heads/353-applyPermissions 从多个 src 接收。但这一个有效:

git push origin 353-applyPermissions:353-applyPermissions
于 2020-02-02T08:45:46.063 回答
0

按照这个 git old patch (2007!)中的解释

一些 refs 变得陈旧,例如当 forkee 重新定位并丢失了 fork 所需的一些对象时。
处理这些 ref 的快速而肮脏的方法是删除它们并再次推送它们。

但是,git-push首先会首先获取 ref 的当前提交名称,由于 ref 未指向有效对象,因此会收到 null sha1,然后告诉receive-pack它应该删除具有此提交名称的 ref。
delete_ref()随后将被调用,并检查resolve_ref()检查对象的有效性)是否返回相同的提交名称。这会失败。

refs/heads/refs/heads/master看起来像一个错误地命名为“refs/heads/master”的分支(使用命名空间来定义分层分支名称),并且没有指向任何内容。
删除它是正确的举动。

于 2012-11-15T08:00:21.193 回答
0

就我而言,我有一个与分支名称同名的标签。重命名分支名称和作品。

于 2018-08-30T07:29:35.410 回答