如何从 Git 中删除无效的远程分支引用?
在我当前的存储库中,我有以下输出:
$ git branch -a
* master
remotes/origin/master
remotes/public/master
我想从分支列表中删除 remotes/public/master
:
$ git branch -d remotes/public/master
error: branch 'remotes/public/master' not found.
另外, git remote
的输出很奇怪,因为它未列出public
:
$ git remote show
origin
如何从分支列表中删除'remotes/public/master'?
更新,尝试了git push
命令:
$ git push public :master
fatal: 'public' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
In my current repo I have the following output:
$ git branch -a
* master
remotes/origin/master
remotes/public/master
I want to delete remotes/public/master
from the branch list:
$ git branch -d remotes/public/master
error: branch 'remotes/public/master' not found.
Also, the output of git remote
is strange, since it does not list public
:
$ git remote show
origin
How can I delete 'remotes/public/master' from the branch list?
Update, tried the git push
command:
$ git push public :master
fatal: 'public' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
我在这里尝试了一切,但没有任何效果。 如果所有其他方法都失败,请从文本文件“.git/packed-refs”中删除有问题的分支,然后从“.git\refs\remotes\origin”中删除有问题的分支
I tried everything here and nothing worked. If all else fails, remove the offending branches from the text file '.git/packed-refs', then remove the offending branches from '.git\refs\remotes\origin<branchName>'
您可能需要清理:
或者您可能需要修剪:
然而,看来这些应该早点清理干净
因此,可能是您手动编辑了配置文件,但这种情况没有发生,或者您遇到了权限问题。
也许再次运行一下,看看会发生什么。
建议上下文
如果您查看修订日志,您会注意到我建议了更多“正确”的技术,这些技术对于不管出于什么原因不想在他们的存储库上工作。
我怀疑OP做了一些事情,导致他们的树处于不一致的状态,导致它的行为有点奇怪,并且需要 git gc 来修复遗留的问题。
通常
gitbranch -rd origin/badbranch
足以破坏本地跟踪分支,或者git push origin :badbranch
足以破坏远程分支,并且通常你将永远需要调用git gc
You might be needing a cleanup:
or you might be needing a prune:
However, it appears these should have been cleaned up earlier with
So it might be you hand-edited your config file and this did not occur, or you have privilege problems.
Maybe run that again and see what happens.
Advice Context
If you take a look in the revision logs, you'll note I suggested more "correct" techniques, which for whatever reason didn't want to work on their repository.
I suspected the OP had done something that left their tree in an inconsistent state that caused it to behave a bit strangely, and
git gc
was required to fix up the left behind cruft.Usually
git branch -rd origin/badbranch
is sufficient for nuking a local tracking branch , orgit push origin :badbranch
for nuking a remote branch, and usually you will never need to callgit gc
您需要做的就是
它将删除所有远程删除的本地分支。
如果你使用的是 git 1.8.5+,你可以自动设置
或者
All you need to do is
It'll remove all your local branches which are remotely deleted.
If you are on git 1.8.5+ you can set this automatically
or
正如 Kent Fredric 所指出的,这将删除名为
master
的远程分支。列出远程跟踪分支:
删除远程跟踪分支:
This would delete the remote branch named
master
as Kent Fredric has pointed out.To list remote-tracking branches:
To delete a remote-tracking branch:
您所需要做的就是
这么简单。 没有理由在这里调用 gc。
All you need to do is
It's that simple. There is no reason to call a gc here.
git gc --prune=now
不是你想要的。远程源
或
git Remote prune origin
# 如果这就是您想要的git gc --prune=now
is not what you want.or
git remote prune origin
# if thats the the remote sourceis what you want
当裁判拥挤时,接受的答案对我不起作用。 然而,这确实:
The accepted answer didn't work for me when the ref was packed. This does however:
就我而言,我试图删除保存在 .git/packed-refs 中的条目。 您可以编辑此纯文本文件并从中删除 git br -D 不知道如何触摸的条目(至少在版本 1.7.9.5 中)。
我在这里找到了这个解决方案: https://stackoverflow.com/a/11050880/1695680
In my case I was trying to delete entries that were saved in
.git/packed-refs
. You can edit this plain text file and delete entries from it thatgit br -D
doesn't know how to touch (At least in ver 1.7.9.5).I found this solution here: https://stackoverflow.com/a/11050880/1695680
引用自:http://www.gitguys.com/topics/adding -并删除远程分支/
Referenced from: http://www.gitguys.com/topics/adding-and-removing-remote-branches/
我不知道 gitbranch-rd,所以我自己解决此类问题的方法是将我的存储库视为远程存储库并进行远程删除。 git 推送 . :refs/remotes/public/master。 如果其他方法不起作用,并且您想要删除一些奇怪的参考,那么这种原始方法肯定会成功。 它为您提供了删除(或创建!)任何类型参考的精确度。
I didn't know about
git branch -rd
, so the way I have solved issues like this for myself is to treat my repo as a remote repo and do a remote delete.git push . :refs/remotes/public/master
. If the other ways don't work and you have some weird reference you want to get rid of, this raw way is surefire. It gives you the exact precision to remove (or create!) any kind of reference.我有类似的问题。 所有答案都没有帮助。 就我而言,我永久显示了两个已删除的远程存储库。
我的最后一个想法是手动删除所有对它的引用。
假设存储库称为“Repo”。 我这样做了:
所以,我从 .git 文件夹中删除了相应的文件和目录(这个文件夹可以在你的 Rails 应用程序或计算机上找到 https://stackoverflow.com/a/19538763/6638513)。
然后我做了:
这找到了一些文本文件,我在其中删除了相应的行。
现在,一切似乎都很好。
通常,你应该把这项工作留给 git。
I had a similar problem. None of the answers helped. In my case, I had two removed remote repositories showing up permanently.
My last idea was to remove all references to it by hand.
Let's say the repository is called “Repo”. I did:
So, I deleted the corresponding files and directories from the .git folder (this folder could be found in your Rails app or on your computer https://stackoverflow.com/a/19538763/6638513).
Then I did:
This found some text files in which I removed the corresponding lines.
Now, everything seems to be fine.
Usually, you should leave this job to git.
只是略有相关,但在与我们相同的情况下仍然可能有帮助 - 我们为远程存储库使用网络文件共享。 上周一切正常,本周我们收到错误“远程源没有为分支 refs/heads/master 宣传 Ref。此 Ref 可能不存在于远程中,或者可能被权限设置隐藏”,
但我们相信什么也没有发生。做了腐败的事情。 NFS 会进行快照,因此我查看了每个“以前的版本”,发现三天前,存储库的大小(以 MB 为单位)已从 282MB 变为 33MB,并且现在存在大约 1,403 个新文件和 300 个文件夹。 我询问了我的同事,其中一位同事那天尝试过推送 - 然后取消了。
我使用 NFS“恢复”功能将其恢复到该日期之前,现在一切又恢复正常了。 我之前确实尝试过修剪,似乎没有帮助。 也许更严厉的清理工作会奏效。
希望有一天这可以帮助别人!
杰伊
Only slightly related, but still might be helpful in the same situation as we had - we use a network file share for our remote repository. Last week things were working, this week we were getting the error "Remote origin did not advertise Ref for branch refs/heads/master. This Ref may not exist in the remote or may be hidden by permission settings"
But we believed nothing had been done to corrupt things. The NFS does snapshots so I reviewed each "previous version" and saw that three days ago, the size in MB of the repository had gone from 282MB to 33MB, and about 1,403 new files and 300 folders now existed. I queried my co-workers and one had tried to do a push that day - then cancelled it.
I used the NFS "Restore" functionality to restore it to just before that date and now everythings working fine again. I did try the prune previously, didnt seem to help. Maybe the harsher cleanups would have worked.
Hope this might help someone else one day!
Jay
不知道我是如何陷入困境的,但我的错误消息略有不同:
但我能够通过稍微重新解释此页面上其他地方的修复来修复它。 我的意思是我用关键字
HEAD
替换了/
中的分支名称。 人们提到的其他建议都不起作用(gc
、prune
等),所以我已经没有想法了,希望得到最好的结果。 不管怎样,它就像一个魅力:Not sure how I got into the mess, but my error message was slightly different:
But I was able to fix it by slightly reinterpreting a fix from elsewhere on this page. By this I mean I substituted the keyword
HEAD
for the branch name in<remote>/<branch>
. None of the other suggestions people mentioned had worked (gc
,prune
, etc.) so I was running out of ideas and hoping for the best. Anyway, it worked like a charm: