Git:警告:refname 'master' 不明确

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

Git: warning: refname 'master' is ambiguous

git

提问by Tim

I saw a few people asking the same question on here but it seems none of their advice is applicable to me. I'm getting the warning that is in the title of this but I don't have any tags named "master". This is the result of git branch -a:

我看到一些人在这里问同样的问题,但似乎他们的建议都不适用于我。我收到了标题中的警告,但我没有任何名为“master”的标签。这是结果git branch -a

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

Any idea what could be going wrong here? I've only been using git for a few months now, so it mostly just worries me that this ambiguity might mess with the repo in the future.

知道这里可能出了什么问题吗?我现在只使用 git 几个月了,所以我主要担心这种歧义可能会在未来干扰 repo。

回答by Magnus

For me I tracked down the source of this warning to much earlier when I incorrectly issued an "update-ref" command. If you forget to specify the full refs/heads/mybranchname path in the first arg, then a file .git/mybranchname gets created, which later leads to this warning when you try to switch to that branch.

对我来说,当我错误地发出“update-ref”命令时,我更早地追踪了此警告的来源。如果您忘记在第一个 arg 中指定完整的 refs/heads/mybranchname 路径,则会创建一个文件 .git/mybranchname,稍后当您尝试切换到该分支时会导致此警告。

It is solved by simply deleting the .git/mybranchname, eg:

只需删除 .git/mybranchname 即可解决,例如:

rm .git/master

And for reference, the correct form for the update-ref command is:

作为参考,update-ref 命令的正确形式是:

git update-ref refs/heads/mybranchname mytargetbranch

Don't forget the "refs/heads" part!

不要忘记“refs/heads”部分!

Also, my most common use-case for update-ref is simply manually moving a branch to point to another commit, which I've found a simpler syntax to do:

此外,我最常见的 update-ref 用例只是手动移动一个分支以指向另一个提交,我发现这是一个更简单的语法:

git branch -f myBranchToMove destinationBranchOrHash

git branch -f myBranchToMove destinationBranchOrHash

This syntax is easier for me because it doesn't require that error-prone refs/heads path qualifier.

这种语法对我来说更容易,因为它不需要容易出错的 refs/heads 路径限定符。

回答by VonC

As detailed in "Git: refname 'master' is ambiguous", that means that, beside heads/master, you have another master in one of the following namespace within the git repo:

正如“ Git: refname ' master' is ambiguous”中所详述的那样,这意味着,除此之外heads/master,您在 git repo 的以下命名空间之一中还有另一个 master:

refs/<refname> 
refs/tags/<refname>
refs/heads/<refname>
refs/remotes/<refname>
refs/remotes/<refname>/HEAD

Or even ./<refname>, as mentioned in Magnus's answer.

甚至./<refname>,正如Magnus回答中提到的那样。

回答by u5819157

git fetch --prune

git pull origin branch-name

should fix your problem.

应该可以解决您的问题。

回答by manman

For future reference, I had the same issue and what ended up to work for me was the solution described here. Basically, when you get Git: warning: refname 'xxx' is ambiguouswarning, you can use: git show-ref xxxto check the references to xxxbranch and validate which ones are having conflict.

为了将来参考,我遇到了同样的问题,最终对我有用的是这里描述的解决方案。基本上,当您收到Git: warning: refname 'xxx' is ambiguous警告时,您可以使用:git show-ref xxx检查对xxx分支的引用并验证哪些存在冲突。

In my scenario, it was a tag named xxxand branch name with the same name. The tag had been made by mistake and was removed from server so all I needed to do was to update my local tag to match the server: git fetch -p -P. This command is explained in details here

在我的场景中,它是一个名称xxx和分支名称相同的标签。该标签是错误制作的并已从服务器中删除,因此我需要做的就是更新我的本地标签以匹配服务器:git fetch -p -P。此命令在此处详细说明

回答by Scott Warren

I had a similar problem (not master) when I created a branch with the same name as a tag.

当我创建一个与标签同名的分支时,我遇到了类似的问题(不是 master)。

This helped me remove the tag https://stackoverflow.com/a/5480292/150953

这帮助我删除了标签https://stackoverflow.com/a/5480292/150953

git push --delete origin tagname