简体   繁体   English

Git - 如何从结帐自动完成中删除分支

[英]Git - how to remove branch from checkout autocomplete

I've deleted some local branches via git branch -d branchname , but they are still exist in autocomplete (when I put git checkout , then press tab key, I see all deleted branches in list).我已经通过git branch -d branchname删除了一些本地分支,但它们仍然存在于自动完成中(当我放置git checkout ,然后按tab键时,我会在列表中看到所有已删除的分支)。

I've tried to make git gc and git prune , but nothing changes.我尝试制作git gcgit prune ,但没有任何变化。

TL;DR - the real answer: TL; DR - 真正的答案:

$ git remote prune origin

Slightly more details:稍微详细一点:

git branch -d foo-branch will fail to delete if foo-branch is not merged into your current branch.如果 foo-branch 未合并到您当前的分支中,则git branch -d foo-branch将无法删除。

It's also a good idea to clean up old branches on a remote if they've already been merged.如果它们已经合并,清理远程上的旧分支也是一个好主意。 You can do this from the commandline by git push origin :foo-branch .您可以通过git push origin :foo-branch从命令行执行此操作。

However, the old "phantom" branch foo-branch will linger for autocompleting git checkout.但是,旧的“幻影”分支 foo-branch 将用于自动完成 git checkout。 Apparently git is caching the branches available on the remote.显然 git 正在缓存远程可用的分支。 By calling:通过调用:

$ git remote prune origin

You can clear the local cache of what branches are available on the git remote.您可以清除 git remote 上可用分支的本地缓存。

I can reproduce the OP's issue for git 2.2.1 (and probably earlier versions) on OSX.我可以在 OSX 上为 git 2.2.1(可能还有更早的版本)重现 OP 的问题。

If you are sure that you do not want the branch, you can remove it from your local and the remote like this:如果你确定你不想要这个分支,你可以像这样从本地远程删除它:

$ git branch -D branchname
$ git push origin :branchname

Then it will stop appearing in autocomplete results.然后它将停止出现在自动完成结果中。

You've probably tried to delete an unmerged branch, so git branch -d branchname has not deleted it.您可能已尝试删除未unmerged分支,因此git branch -d branchname尚未删除它。 You can check if the branch still exists with:您可以使用以下命令检查分支是否仍然存在:

git branch -a

If you're really sure to delete the ~branch even if is not merged` you can force the deletion with:如果您真的确定要删除 ~branch, even if is not合并也可以使用以下命令强制删除:

git branch -D branchname

I had this problem and the previous solutions didn't work for me.我遇到了这个问题,以前的解决方案对我不起作用。 It turned out that I had a tag in the repo with the same name as the old deleted branch.事实证明,我在 repo 中有一个与旧的已删除分支同名的标签。 You can delete the tag with:您可以使用以下命令删除标签:

git tag -d [tagname]

To delete it remotely:要远程删除它:

git push origin :refs/tags/[tagname]

Thanks to https://nathanhoad.net/how-to-delete-a-remote-git-tag感谢https://nathanhoad.net/how-to-delete-a-remote-git-tag

Note that pushing the branch deletion ( git push origin :branchname ) is easier in Git 2.13 (Q2 2017), since the completion script learned to complete " git push --delete b<TAB> " (to complete branch name to be deleted).请注意,在 Git 2.13(2017 年第二季度)中git push origin :branchname分支删除( git push origin :branchname )更容易,因为完成脚本学会了完成“ git push --delete b<TAB> ”(完成要删除的分支名称) .

See commit 723c1d5 (22 Apr 2017) by Ævar Arnfjörð Bjarmason ( avar ) .请参阅Ævar Arnfjörð Bjarmason ( avar ) 提交的 723c1d5 (2017 年 4 月 22 日
(Merged by Junio C Hamano -- gitster -- in commit f70b541 , 26 Apr 2017) (由Junio C gitster合并gitster提交 f70b541 中,2017 年 4 月 26 日)

I realize this is really, really old, but I just ran into this issue, and in my case, I had pruned the branches in origin , but not the ones in origin-http .我意识到这真的非常旧,但我刚刚遇到了这个问题,就我而言,我已经修剪了origin的分支,但没有修剪origin-http的分支。

I don't normally use http for cloning, so this is not typically an issue, but...welp.我通常不使用 http 进行克隆,所以这通常不是问题,但是......好吧。

Once I did git remote prune origin-http , it fixed the problem for me.一旦我做了git remote prune origin-http ,它就为我解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM