我认为这可能是重复的,但我找不到我当前问题的直接答案。
我试图让我的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
答案 0 :(得分:1)
在我的git-completion.bash
版本中,我可以执行以下操作以防止这些已删除的分支显示为完成的一部分:
export GIT_COMPLETION_CHECKOUT_NO_GUESS=1
我在文件(自制-/usr/local/Cellar/git/2.19.2/share/zsh/site-functions/git-completion.bash
)和SO帖子Disable auto-completion of remote branches in Git Bash?中都提到了它。
答案 1 :(得分:0)
我无法在最小的测试中重复这一点。也许是一个已修复的错误?或者你在某种程度上有标签或遥控器?我刚用这样的本地分支测试过,看起来和你的测试类似。在deleteme分支消失的最后一步,它不再显示在选项卡完成中。 Git版本1.8.5.2(Apple Git-48)和当前github git的完成。最新的OSX默认bash。
$ git branch
* master
$ git checkout -b deleteme
Switched to a new branch 'deleteme'
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
$ git checkout deleteme
Switched to branch 'deleteme'
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
#completion worked for all those checkouts
$ git branch -D deleteme
Deleted branch deleteme (was e7b6bcd).
#completion does not find any branch with de* anymore - tab-tab shows dirs in the repo
$ git checkout de
demos/ deps/