使用git pull失败 "无法找到远程引用xxx"

23

我提出了一个关于git pull的问题。

首先,我在“test_http_1204”分支中,

root@inception-server-Quantal:~/bosh# git branch
              master
            * test_http_1204
              ubuntu1204

然后我使用git pull命令,但是收到了一个错误消息。
 root@inception-server-Quantal:~/bosh# git pull m109bosh test_http_1204
    fatal: Couldn't find remote ref test_http_1204
    Unexpected end of command stream

但是,在我的远程仓库"m109bosh"中,我可以找到分支"test_http_1204"。

root@inception-server-Quantal:~/bosh# git branch -a
  master
* test_http_1204
  ubuntu1204
  remotes/m109bosh/master
  remotes/m109bosh/patch-1
  remotes/m109bosh/test_http_1204
  remotes/m109bosh/ubuntu1204
  remotes/origin/HEAD -> origin/master
  remotes/origin/floating_dns_registry
  remotes/origin/http_stemcell_uploader
  remotes/origin/master
  remotes/origin/squashed
  remotes/origin/ubuntu1204
  remotes/origin/upstream

而且,.git/config的内容如下所示:

  root@inception-server-Quantal:~/bosh# cat .git/config 
    [core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
    [remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = https://github.com/cloudfoundry-community/bosh-cloudstack-cpi.git
    [branch "master"]
        remote = origin
        merge = refs/heads/master
    [branch "ubuntu1204"]
        remote = origin
        merge = refs/heads/ubuntu1204
    [remote "m109bosh"]
        url = https://github.com/m1093782566/bosh-cloudstack-cpi.git
        fetch = +refs/heads/*:refs/remotes/m109bosh/*
        url = https://github.com/m1093782566/bosh.git

我猜根本原因可能是.git/config中缺少[branch "test_http_1204"],但是即使我手动添加这些行到.git/config,它仍然不起作用。
[branch "test_http_1204"]
        remote = m109bosh
        merge = refs/heads/test_http_1204

我对此毫无头绪。请问您能告诉我如何解决吗?谢谢!

尝试:git ls-remote m109bosh。我认为问题在于远程m109bosh曾经有一个test_http_1024,但现在已经没有了。 - torek
是的,这表明远程仓库有分支masterpatch-1ubuntu1024 - torek
解决了!谢谢!因为远程仓库“m109bosh”有两个URL! - dj199008
啊哈,是的。它只会使用其中之一。 - torek
1个回答

21

根据git ls-remote的输出(之前在注释中,现在已经不再合适了),看起来远程仓库曾经有一个名为test_http_1024的分支,但现在已经不存在了。

换句话说,无论谁控制这个远程仓库,都使用git branch -d或类似的命令删除了他们的test_http_1024分支。这意味着当您要求git pull提取该分支的内容时,它只能告诉您:“什么?哪个分支?” :-)

当您查看自己所拥有的远程分支集时,可以看到它们曾经有一个分支test_http_1024(在其存在时由git复制到remotes/m109bosh/test_http_1204),但是他们可以随时添加或删除分支。

如果您运行git fetch -p m109boshgit remote update --prune m109bosh,您自己的git将删除其对test_http_1024分支的旧而陈旧的副本。(如果您仍在使用该副本,则可能不想这样做。)


也许更重要的问题是,在:

[remote "m109bosh"]
    url = https://github.com/m1093782566/bosh-cloudstack-cpi.git
    fetch = +refs/heads/*:refs/remotes/m109bosh/*
    url = https://github.com/m1093782566/bosh.git

有两个不同的url=行,很可能其中一个已经过时了。 (git fetch使用第一个,所以也许你想用第二个。)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接