Git: warning: refname 'master' is ambiguous

匿名 (未验证) 提交于 2019-12-03 01:58:03

问题:

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   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.

回答1:

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.

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

rm .git/master 

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

git update-ref refs/heads/mybranchname mytargetbranch 

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

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:

git branch -f myBranchToMove destinationBranchOrHash

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



回答2:

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:

refs/  refs/tags/ refs/heads/ refs/remotes/ refs/remotes//HEAD 

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



回答3:

git fetch --prune  git pull origin branch-name 

should fix your problem.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!