我如何让 git 补全向我显示提交名称?

我如何让 git 补全向我显示提交名称?

我对 Git 和 Zsh 中的完成有些不明白。

我在 Windows 机器上使用 Git(Windows 版 v2.11)和 Cygwin 以及 Zsh(带 Babun)。当我键入git checkout并双击时TAB,我得到了分支和对象名称的完成提示:

太棒了!现在,在我的 OS X 机器上安装了 Git(Mac 版 2.13.0,通过 Homebrew 安装)和 Zsh,当我输入git checkout并双击TAB时,我只得到这个:

第一个提示中的功能来自哪里?换句话说,我必须在 OS X / Zsh 下安装什么才能实现这一点?

我尝试过的一些方法:

  • 我已经排除了 Oh-my-Zshgit插件造成的问题,因为当我在 Windows/Cygwin 下禁用该插件时,我仍然得到相同的奇特完成效果。
  • 在 Windows 中,我所要做的就是以空开始,.zshrc以便使此完成工作运行autoload -U compinit && compinit
  • 我尝试添加fpath=(/usr/local/share/zsh/site-functions/ $fpath)到我的,.zshrc希望它能够获取 Homebrew 安装的内容(如输出中提到的brew info git),但它并没有改变任何东西。
  • 我尝试zsh-completions从 Homebrew 安装,并按照建议添加fpath=(/usr/local/share/zsh-completions $fpath)到我的.zshrc。仍然没有变化。
  • 更让我困惑的是,最近我使用了一个不太了解 Git 的同事的 MacBook。他只安装了 Git。他没有配置任何东西就获得了相同的扩展完成。
  • 我的.zcompdump,如果这有帮助的话:https://pastebin.com/raw/UzrZ2NqD
  • 我的.zshrchttps://github.com/slhck/dotfiles/blob/master/.zshrc

git当我输入,然后Ctrl-X,然后 时,OS X 中出现了更多调试输出h

tags in context :completion::complete:git::
    argument-1 options  (_arguments __git_zsh_main _git)
    use-compctl         (_default _git)
    globbed-files       (_files _default _git)
tags in context :completion::complete:git:argument-1:
    alias-commands common-commands all-commands  (__git_zsh_main _git)
    alias-commands                               (__git_zsh_cmd_alias __git_zsh_main _git)
    common-commands                              (__git_zsh_cmd_common __git_zsh_main _git)
    all-commands                                 (__git_zsh_cmd_all __git_zsh_main _git)

而当我在 Windows/Cygwin 上执行相同操作时,我得到:

tags in context :completion::complete:git::
    argument-1 options  (_arguments _git)
tags in context :completion::complete:git:argument-1:
    aliases main-porcelain-commands user-commands third-party-commands ancillary-manipulator-commands ancillary-interrogator-commands interaction-commands plumbing-manipulator-commands plumbing-interrogator-commands plumbing-sync-commands plumbing-sync-helper-commands plumbing-internal-helper-commands  (_git_commands _git)

输出ls -l ${^fpath}/_git

ls: /Users/werner/.oh-my-zsh/completions/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/functions/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/brew/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/docker-compose/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/docker/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/gem/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/git-extras/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/git-flow/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/git/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/github/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/osx/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/python/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/rails/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/ruby/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/svn/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/vagrant/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/virtualenv/_git: No such file or directory
ls: /usr/local/share/zsh-completions/_git: No such file or directory
-rw-r--r--  1 werner  admin  336270 Dec 21 19:42 /usr/local/Cellar/zsh/5.3.1/share/zsh/functions/_git
lrwxr-xr-x  1 werner  admin      56 May 18 17:26 /usr/local/share/zsh/site-functions/_git -> ../../../Cellar/git/2.13.0/share/zsh/site-functions/_git
lrwxr-xr-x  1 werner  admin      56 May 18 17:26 /usr/local/share/zsh/site-functions/_git -> ../../../Cellar/git/2.13.0/share/zsh/site-functions/_git
lrwxr-xr-x  1 werner  admin      56 May 18 17:26 /usr/local/share/zsh/site-functions/_git -> ../../../Cellar/git/2.13.0/share/zsh/site-functions/_git

答案1

不确定到底出了什么问题,但以下是我解决问题的方法:

首先,确保打开终端并启动 Bash ( /bin/bash),然后:

brew uninstall zsh
rm -rf /usr/local/share/zsh/site-functions
brew install zsh

但显然,重新安装 Git 会导致同样的问题再次出现:

brew reinstall git

一旦我这样做了,补全就会恢复到简化形式。如果是这种情况,您可以删除 Homebrew 安装的 Git 补全:

rm /usr/local/share/zsh/site-functions/git-completion.bash
rm -rf /usr/local/share/zsh/site-functions/_git

这将使扩展的完成再次出现。

答案2

我知道这是一个非常老的话题,但我希望它能帮助到下一个人。OSX 上的 Git 的自制版本存在问题,导致 git-extras 补全中断。如果您卸载此版本,它会再次正常工作。您可能能够运行另一个版本,但至少自制版本肯定被破坏了。

编辑:我知道内置版本(git 版本 2.37.1(Apple Git-137.1))运行良好。我有 HomeBrew 2.44.0 的最新版本

操作系统:macOS 12.6.3 21G419 arm64 主机:MacBookPro18,3 内核:21.6.0 终端:iTerm2

相关内容