git - macos git autocomplete 显示删除的分支

标签 git

我认为这可能是重复的,但我找不到我当前问题的直接答案。

我正在尝试让我的 macosx git autocomplete 工作起来类似于我在 linux 机器上工作的 git autocomplete。我找到了一些指导我安装 https://github.com/git/git/tree/master/contrib/completion 的说明(我使用的是 .bash 版本)。一切正常,唯一的问题是现在自动完成显示已删除的分支。

有没有人有替代脚本/方法,或者甚至只是关于如何编辑当前脚本以避免显示我的所有分支以及仅显示可用的当前本地分支的说明。

谢谢你 布罗迪

[编辑]

我认为可以举个例子来帮助使问题更清楚。

#result of git branch is as expected
$ git branch
 *master
  somefeature
  someotherfeature

#now I delete one of my feature branches
$ git branch -D someotherfeature
$ git branch
 *master
  somefeature
  #the branch someotherfeature is gone, as expected

#however when I attempt an autocomplete, like with git checkout, I get everything remote branches, local branches, and previously deeted branches.
$ git checkout <tab><tab>
  master    somefeature    someotherfeature    remote/origin/master    remote/origin/remotebranch 

我想让它像在我的 linux 机器上一样显示我的本地分支

# i.e. given 2 local branches `master` and `somefeature` autocomplete would work as follows
$ git checkout <tab><tab>
  master    somefeature

最佳答案

在我的 git-completion.bash 版本中,我可以执行以下操作来防止这些已删除的分支显示为完成的一部分:

export GIT_COMPLETION_CHECKOUT_NO_GUESS=1

我发现它在文件 (homebrew - /usr/local/Cellar/git/2.19.2/share/zsh/site-functions/git-completion.bash) 和也在SO 帖子 Disable auto-completion of remote branches in Git Bash? .

关于git - macos git autocomplete 显示删除的分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23569688/

相关文章:

Git:构建具有多个分支的项目

git submodule sync 命令 - 它有什么用?

Git Checkout [Tab] 显示很多分支

git 推送错误 -> ! [远程拒绝] HEAD -> refs/master (ref 存在)

git - 提交修改如何帮助您在 Git 中切换分支?

git - 在 GIT 上推送更改时出错。引用名称必须遵循 git ref-format 规则

git - 如何从特定提交继续项目并修复 HEAD 分离问题?

git - 如何删除TortoiseGit中的URL历史记录?

git - 关于 git pull --rebase 的困惑

git - git svn 与 git 子树兼容吗?