我在用zsh https://www.zsh.org with 哦我的zsh https://github.com/robbyrussell/oh-my-zsh在 Ubuntu 18.04.2 上。现在,Git https://git-scm.com安装在版本 2.20.1 上。
每当我想要checkout
来自远程的本地分支(origin
)我尝试在 shell 中使用制表符补全,如下所示:
git checkout fea<TAB>
选项卡补全结果如下:
git checkout origin/feature
我对选项卡补全的实际期望是:
git checkout feature
如何配置选项卡完成以正确(?)完成远程分支 - 或者我遗漏了什么?我的dotfiles https://github.com/johnjohndoe/dotfiles是公开的。
回复塔伦·拉尔瓦尼的评论 https://stackoverflow.com/questions/55717217/how-to-use-zsh-tab-completion-on-git-without-origin#comment100155717_55717217:输出git branch -a
is:
develop
* 客房服务
远程/起源/HEAD -> 起源/开发
遥控器/起源/开发
遥控器/原点/主控
遥控器/来源/发布
遥控器/来源/功能
经过深入研究后发现,完成git checkout
ZSH 下的不满足哦我的zsh,但从_git
shell 设施提供的功能。
正如评论中所述,我无法重现您遇到的问题。一切似乎都按预期进行。尽管如此…
查看以下文件:
/usr/share/zsh/<5.x>/functions/_git
我当地的zsh版本是5.2。绕行450,你可以看到:
case $state in
(branch-or-tree-ish-or-file)
# TODO: Something about *:: brings us here when we complete at "-". I
# guess that this makes sense in a way, as we might want to treat it as
# an argument, but I can't find anything in the documentation about this
# behavior.
[[ $line[CURRENT] = -* ]] && return
if (( CURRENT == 1 )) && [[ -z $opt_args[(I)--] ]]; then
# TODO: Allow A...B
local branch_arg='' \
remote_branch_noprefix_arg='remote branches::__git_remote_branch_names_noprefix' \
tree_ish_arg='tree-ishs::__git_tree_ishs' \
file_arg='modified-files::__git_modified_files'
if [[ -n ${opt_args[(I)-b|-B|--orphan|--detach]} ]]; then
remote_branch_noprefix_arg=
file_arg=
elif [[ -n $opt_args[(I)--track] ]]; then
branch_arg='remote-branches::__git_remote_branch_names'
remote_branch_noprefix_arg=
tree_ish_arg=
file_arg=
elif [[ -n ${opt_args[(I)--ours|--theirs|-m|--conflict|--patch]} ]]; then
remote_branch_noprefix_arg=
fi
_alternative \
$branch_arg \
$remote_branch_noprefix_arg \
$tree_ish_arg \
$file_arg && ret=0
删除传递给的数组之一_alternative
更改之后填写分支名称时向您建议的内容git checkout
。特别是,删除$remote_branch_noprefix_arg
返回带有前缀的远程分支名称origin
或其各自的远程存储库名称。
因此,升级您的 shell 或降级到以前的版本可能是一个好主意。
还有一些细节:
- 我看到你已经编辑了原来的帖子并且
git push
有充分的理由以稍微不同的方式工作git checkout
;
- 远程分支的同源本地分支可能不会强制存在:
feature
不同于origin/feature
,即使前一个存在,通常配置为跟踪后者;
- 默认情况下,如果本地分支尚不存在并且没有显式选项被忽略,则签出
feature
将创建一个同名本地分支,配置为跟踪远程分支,然后在签出时切换到该分支origin/feature
将使您处于分离模式,允许浏览此远程分支但直接在其之上提交。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)