git 如何从自动完成中删除已删除的分支名称?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17933401/
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 do I remove deleted branch names from autocomplete?
提问by John Hoffman
I used git branch -d myBranch
to delete a branch. However, when I am on master and try to checkout a new branch with git checkout
, myBranch
still appears in the tab-autocomplete.
我曾经git branch -d myBranch
删除一个分支。但是,当我在 master 上并尝试使用 签出新分支时git checkout
,myBranch
仍然出现在选项卡自动完成中。
How do I remove the name myBranch
from tab-autocomplete for git checkout
?
如何myBranch
从选项卡自动完成中删除名称git checkout
?
采纳答案by twalberg
One possible reason for this is that, if a remote branch (e.g. origin/myBranch
) still exists, then git checkout myBranch
will succeed as an alternative to git checkout -b myBranch origin/myBranch
. This is intended as a convenience for the common case of checkout out a remote branch for the first time, creating an identically named local tracking branch.
一个可能的原因是,如果远程分支(例如origin/myBranch
)仍然存在,那么git checkout myBranch
作为git checkout -b myBranch origin/myBranch
. 这是为了方便第一次检出远程分支的常见情况,创建一个同名的本地跟踪分支。
There are other possibilities, too, depending on what exactly you are using for completion, but that's one of the first things I'd check. If you run git branch -a
, and there is an origin/myBranch
listed (or one for a remote other than origin
, if you have such), then that's a likely culprit.
还有其他可能性,具体取决于您用于完成的确切内容,但这是我要检查的第一件事。如果您运行git branch -a
,并且有一个origin/myBranch
列出的(或一个用于远程以外的origin
,如果您有这样的),那么这可能是罪魁祸首。
回答by ericsoco
git fetch --prune --all
git fetch --prune --all
Posting this as its own answer since it's a one-line fix, but if you vote be sure to vote for @twalberg's answer above.
将此作为自己的答案发布,因为它是一个单行修复程序,但如果您投票,请务必投票支持上面@twalberg 的答案。
@twalberg's suggestion to git branch -a
led me on the right track; my coworker suggested git fetch --prune --all
to prune all the dead branches from all the remotes, which is useful when working with lots of devs with lots of forks.
@twalberg 的建议让git branch -a
我走上正轨;我的同事建议git fetch --prune --all
修剪所有遥控器上的所有死分支,这在与许多具有大量分支的开发人员一起工作时非常有用。