Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
425 views
in Technique[技术] by (71.8m points)

git - 如何从Git中删除无效的远程分支引用?(How do you remove an invalid remote branch reference from Git?)

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:

(我想从分支列表中删除remotes/public/master :)

$ 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的输出很奇怪,因为它没有列出public :)

$ git remote show 
origin

How can I delete 'remotes/public/master' from the branch list?

(如何从分支列表中删除“remotes / public / master”?)

Update, tried the git push command:

(更新,尝试了git push命令:)

$ git push public :master
fatal: 'public' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
  ask by cmcginty translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

(删除<name>下的所有陈旧跟踪分支。)

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

(这些陈旧的分支已从<name>引用的远程存储库中删除,但仍在“remotes / <name>”中本地可用。)

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

(使用--dry-run选项,报告将修剪哪些分支,但不实际修剪它们。)

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

(但是,看起来这些应该早点用)

git remote rm public 

rm

(R M)

Remove the remote named <name>.

(删除名为<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.

(我怀疑OP已经做了一些让他们的树处于不一致状态的东西,导致它表现得有些奇怪,并且需要git gc来修复左后方残骸。)

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 branch -rd origin/badbranch足以用于本地跟踪分支,或者git push origin :badbranch用于核心远程分支, 通常永远不需要调用git gc)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...