如何从Git中删除无效的远程分支引用? [英] How do you remove an invalid remote branch reference from Git?

查看:337
本文介绍了如何从Git中删除无效的远程分支引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我目前的仓库中,我有以下输出:

  $ git分支-a 
* master
remotes / origin / master
remotes / public / master

我想删除 remotes / public / master 来自分支列表:

  $ git branch  - d remotes / public / master 
错误:未找到分支'remotes / public / master'。

另外, git remote 的输出是奇怪的,因为它没有列出 public
$ b

  $ git remote show 
原产地

如何删除'remotes / public / master'分支列表?



更新,尝试了 git push 命令:

  $ git push public:master 
致命的:'public'看起来不是git存储库
致命的:远端挂起意外地出现


解决方案

您可能需要清理

  git gc --prune = now 

或者您可能需要修剪

  git remote prune public 



修剪

删除< name>下的所有陈旧跟踪分支。这些陈旧的分支已从引用的远程存储库中删除,但仍在本地可用于远程/< name>。



- 干运行选项,报告什么分支将被修剪,但没有实际修剪它们。

然而,看起来这些应该有已经被清理过了

  git remote rm public 




rm



删除名为< name& 。远程
的所有远程跟踪分支和配置设置都被删除。

因此,它可能是你手工编辑你的配置文件,这没有发生,或者你有特权问题。

也许再次运行,看看会发生什么。



< h2>建议上下文

如果您查看修订日志 a>,你会注意到我提出了更多正确的技术,无论出于什么原因都不想在他们的存储库上工作。



我怀疑OP做了一些让他们的树处于不一致的状态,导致它的行为有点奇怪,并且 git gc 是修复遗留下来的垃圾所必需的。

通常 git branch -rd origin / badbranch 足够用于核实本地跟踪分支,或者 git push origin:badbranch 用于核对远程分支,而通常你永远不会需要调用 git gc


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

解决方案

You might be needing a cleanup

git gc --prune=now

or you might be needing a prune

git remote prune public

prune

Deletes all stale tracking branches under <name>. These stale branches have already been removed from the remote repository referenced by <name>, but are still locally available in "remotes/<name>".

With --dry-run option, report what branches will be pruned, but do no actually prune them.

However, it appears these should have been cleaned up earlier with

git remote rm public 

rm

Remove the remote named <name>. All remote tracking branches and configuration settings for the remote are removed.

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 , or git push origin :badbranch for nuking a remote branch, and usually you will never need to call git gc

这篇关于如何从Git中删除无效的远程分支引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆