git refname 'origin/master' 不明确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26046698/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:32:22  来源:igfitidea点击:

git refname 'origin/master' is ambiguous

gitgit-svn

提问by gypaetus

I have a git repository that is tracking several remote branches:

我有一个跟踪多个远程分支的 git 存储库:

$ git branch -a
* master
  remotes/git-svn
  remotes/origin/master
  remotes/trunk

When I try to setup a default one I get the following error:

当我尝试设置默认设置时,出现以下错误:

$ git branch --set-upstream-to=origin/master master
warning: refname 'origin/master' is ambiguous.
fatal: Ambiguous object name: 'origin/master'.

I would like to kremove some of the remote master branches but the master references are still there. How can I remove them to be able to set the default upstream branch to origin/master?

我想删除一些远程主分支,但主引用仍然存在。如何删除它们以便能够将默认上游分支设置为origin/master

$ git show-ref master
cba97a58c99743c355b569bbf35636c8823c2d96 refs/heads/master
6726b4985107e2ddc7539f95e1a6aba536d35bc6 refs/origin/master
d83f025cd3800ed7acd76b2e52ae296e33f1cd07 refs/original/refs/heads/master
cba97a58c99743c355b569bbf35636c8823c2d96 refs/remotes/origin/master

回答by jub0bs

The output of git branch -ashows that you have a remote-tracking branch called origin/master. Perfectly normal.

的输出git branch -a显示您有一个名为 的远程跟踪分支origin/master。完全正常。

However, the output of git show-ref mastercontains

但是,输出git show-ref master包含

6726b4985107e2ddc7539f95e1a6aba536d35bc6 refs/origin/master

which indicates that you most likely ran something like the following low-level command:

这表明您很可能运行了以下低级命令:

git update-ref refs/origin/master master

This command creates a branch (pointing at the same commit as master) called origin/master, but living directly under refs/, i.e. outsidethe refs/heads/namespace, where local branches normally live. Quite suspicious... Did you mean to do that?

此命令创建一个名为 的分支(指向与 相同的提交masterorigin/master,但直接位于 下refs/,即位于refs/heads/本地分支通常所在的命名空间之外。很可疑……你是故意这样做的吗?

Such a branch won't get listed by git branch -a. Git is getting confused, though, because it sees two branches whose refnames end with origin/master:

这样的分支不会被git branch -a. 但是,Git 感到困惑,因为它看到两个分支,其 refnames 以 结尾origin/master

  • refs/remotes/origin/master, your remote-tracking branch, and
  • refs/origin/master, the local branch that you created (by accident) outside refs/heads/.
  • refs/remotes/origin/master,您的远程跟踪分支,以及
  • refs/origin/master,您在refs/heads/.之外(偶然)创建的本地分支。

Solution

解决方案

If you did notmean to create refs/origin/master

如果你不是有意创造refs/origin/master

Simply delete it:

只需删除它:

git update-ref -d refs/origin/master

Then, there won't be any ambiguity, and Git will comply when you try to set master's upstream.

然后,不会有任何歧义,当您尝试设置master's upstream时,Git 会遵守。

If you did mean to create refs/origin/master

如果你真的想创造 refs/origin/master

To avoid ambiguity, simply specify the fullrefname of the branch you wish to set as master's upstream:

为避免歧义,只需指定您希望设置为上游的分支的完整引用名称master

git branch --set-upstream-to=refs/remotes/origin/master master


To fix ideas, here is some code that reproduces the situation in one of my GitHub repos:

为了修正想法,这里有一些代码在我的 GitHub 存储库之一中重现了这种情况:

$ cd ~/Desktop
$ git clone https://github.com/Jubobs/gitdags && cd gitdags

$ git update-ref refs/origin/master

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

$ git show-ref master
15b28ec22dfb072ff4369b35ef18df51bb55e900 refs/heads/master
15b28ec22dfb072ff4369b35ef18df51bb55e900 refs/origin/master
15b28ec22dfb072ff4369b35ef18df51bb55e900 refs/remotes/origin/HEAD
15b28ec22dfb072ff4369b35ef18df51bb55e900 refs/remotes/origin/master

$ git branch --set-upstream-to=origin/master master
warning: refname 'origin/master' is ambiguous.
fatal: Ambiguous object name: 'origin/master'.

$ git update-ref -d refs/origin/master
$ git branch --set-upstream-to=origin/master master
Branch master set up to track remote branch master from origin.

回答by Andrew C

You probably accidentally created a local ref called 'origin/master'

您可能不小心创建了一个名为“origin/master”的本地引用

for instance, if you did this

例如,如果你这样做

git branch origin/master

It would lead to this problem. This one looks suspect "refs/origin/master". "refs/heads/master" is your local master, "refs/remotes/origin/master" is your remote branch reference, and "refs/origin/master" is probably a mistake that is screwing you up.

它会导致这个问题。这个看起来很可疑“refs/origin/master”。"refs/heads/master" 是你的本地 master,"refs/remotes/origin/master" 是你的远程分支引用,而 "refs/origin/master" 可能是一个让你搞砸的错误。

You just need to delete that reference (git update-ref -d ) and things will start working again.

您只需要删除该引用 (git update-ref -d ),事情就会重新开始工作。

回答by rymo

I had a very similar problem due to an accidental tag named "master", showing in git show-ref masteras refs/tags/master. The fix in this case was:

由于一个名为“master”的意外标签,我遇到了一个非常相似的问题,显示git show-ref masterrefs/tags/master. 在这种情况下的修复是:

git tag -d master

回答by Sumit Kapoor

I faced same problem few days ago where there were multiple references created of the same branch.

几天前我遇到了同样的问题,同一分支创建了多个引用。

Things i tried:

我尝试过的事情:

> git show-ref (will give you the list of references, from the
> references list you can check if there are multiple references created
> for the branch you are working on or not.)

If there are multiple references created then simply remove it

如果创建了多个引用,则只需将其删除

rm .git/refs/heads/master

After removing the references you can take the checkout of the branch from remote origin only if you have pushed something in it, otherwise you have to redo everything which you did in the branch

删除引用后,只有在推送了某些内容时,您才能从远程源结帐分支,否则您必须重做在分支中所做的一切

git fetch origin
git checkout origin/branchName

This solution worked out for me in case of ambiguous branches.

在分支不明确的情况下,这个解决方案对我有用。