git 如何删除远程源/参考/头/主
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4890772/
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
How to remove remote origin/refs/heads/master
提问by Peter Smit
Don't ask me how but I managed to get accidentally the following remote branches in a git repository:
不要问我是怎么做到的,但我设法在 git 存储库中意外获得了以下远程分支:
$ git branch -r
origin/HEAD -> origin/master
origin/master
origin/refs/heads/master
All are pointing to the same commit. How can I remove the unnecessary listing for origin/refs/heads/master
?
所有都指向同一个提交。如何删除不必要的列表 origin/refs/heads/master
?
I tried to do the following
我尝试执行以下操作
$ git push origin :refs/heads/master
error: dst refspec refs/heads/master matches more than one.
But as shown, this gives an error.
但如图所示,这会产生错误。
采纳答案by Peter Smit
The solution was to delete the branch refs/heads/refs/heads/master
解决办法是删除分支 refs/heads/refs/heads/master
git push origin :refs/heads/refs/heads/master
回答by Cascabel
That's not actually a branch on the remote - it's just a local ref that claims to be representing something on the remote, just as origin/master represents the master branch on the remote. The full name of the ref is refs/remotes/origin/refs/heads/master
. All you have to do to delete it is:
这实际上不是远程上的分支——它只是一个本地引用,声称代表远程上的某些东西,就像 origin/master 代表远程上的主分支一样。ref 的全名是refs/remotes/origin/refs/heads/master
. 删除它所要做的就是:
git branch -r -d origin/refs/heads/master
It's vaguely possible that you managed to push this as well (but you'd have had to try extra hard to do so). If you did, I'd simply listing the refs of origin:
您也有可能设法推动这一点(但您必须更加努力地这样做)。如果你这样做了,我会简单地列出来源的参考:
git ls-remote origin
and then, if there's anything stupid there, using git push origin :<refname>
to get rid of it.
然后,如果那里有什么愚蠢的东西,就用git push origin :<refname>
它来摆脱它。
P.S. If this doesn't do it for you, you're going to want to use git for-each-ref
to see all of your refs, and possibly git ls-remote origin
to see all the remote ones, and track down exactlywhich things don't belong, with their fully qualified refnames.
PS 如果这对您不起作用,您将希望使用git for-each-ref
查看所有参考,并可能git ls-remote origin
查看所有远程参考,并准确追踪哪些东西不属于,以及它们的完全限定参考名称。
回答by jecky dalal
It's
它是
git branch -r -d origin/ref/heads/master
instead of
代替
git branch -r -d origin/refs/heads/master
in the code part to delete branch. There is difference in ref word in the code.
在代码部分删除分支。代码中的 ref 字有所不同。