【问题标题】:git auto-complete doesn't prompt branch namesgit自动完成不提示分支名称
【发布时间】:2018-07-17 09:03:24
【问题描述】:

我尝试了this 线程中提到的所有内容,但当我双击tab 命令键git checkout 时,我只得到以下建议

FETCH_HEAD HEAD ORIG_HEAD

而我期待分支名称。

还有什么其他建议可以让它工作吗?

我在 ubuutu 14.04

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:    14.04
Codename:   trusty

更新

全局 gitconfig 文件

[user]
        email = abc@zxc.com
        name = Abc Zxc
[credential]
        helper = cache --timeout=3600
[filter "lfs"]
        process = git-lfs filter-process
        required = true
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
[diff]
        tool = meld
[merge]
        tool = meld
[difftool]
        prompt = false

git 版本

kishor@kishor-ThinkCentre-E73:~$ git version
git version 1.9.1

bash 完成详情

# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.  

命令输出

git --git-dir=".git" for-each-ref --shell --format="%(refname:short)" refs/tags refs/heads refs/remotes

'160117_whole_flow_demo'
'170109_aws_mgmt_plane'
'170123_django_angular_lib'
'170124_authentication'
'170125_merging_html'
'170206_code_integration'
'170208_ng_code_snippets'
'170214_user_mapping_and_dropdown'
... and so on

附注我在所有其他回购中也面临同样的问题。

【问题讨论】:

  • 请提供minimal reproducible example,以便重现您的问题。根据您当前问题的内容,我必须阅读您的链接,希望您完全按照它所说的去做并得出结论,我无法重现它...
  • @Clijsters,我确实做了那个帖子中提到的同样的事情,我已经在我的旧开发机器上做了同样的事情。我当前 repo 的唯一区别是,它是从网络上的另一台机器复制回来的。
  • 明确一点...git fetch 工作没有任何问题并且 git branch 显示你的分支?
  • 是的,所有 git 命令都可以正常工作。只有我没有得到建议中的分支名称。
  • 你能提供git branch -a的输出吗?

标签: bash git git-completion


【解决方案1】:

我可能是错的,但我认为您尝试使用的 git 版本与您的 git-completion 版本相比太旧了。

你可以试试跑:

git for-each-ref --format="(refname:strip=2)" refs/heads/*

如果没有输出,或者如果有错误,我可能是对的(我希望类似于fatal: unknown refname: format strip=2)。

在这种情况下,要么升级你的 git 版本,要么替换你的 git-completion 以匹配你的 git 版本。如果选择后者,可以使用this version(来自git的github仓库)。

【讨论】:

  • 太棒了!我更喜欢降级 git-completion 脚本。我从您提供的源中复制了脚本并将其保存在 /home 中,并将路径添加到 .bashrc 并且它有效。再次感谢您今天教授新事物。
  • @KishorPawar 我的荣幸 =)
  • 这完美地解决了我的问题。 Stoked 我不必升级 git。注意:我在 1.8.3.1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-02-25
  • 1970-01-01
  • 2013-12-11
  • 2019-09-06
  • 1970-01-01
  • 2018-09-16
  • 1970-01-01
相关资源
最近更新 更多