git 命令在选项卡上自动完成在 Mac 上的子目录中不起作用


$ git co <tabbing not suggesting commands like commit etc.. >

根文件夹中,它可以工作,但不在子目录中

引用自:https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks

自动完成 如果你使用 Bash shell,Git 附带了一个很好的自动完成脚本,你可以启用。直接从 Git 源代码下载它 https://github.com/git/git/blob/master/contrib/completion/git-completion.bash .将此文件复制到您的主目录,并将其添加到您的 .bashrc 文件中:

source ~/git-completion.bash

如果要将 Git 设置为所有用户自动完成 Bash shell,请将此脚本复制到 Mac 系统上的/opt/local/etc/bash_completion.d 目录或 Linux 系统上的/etc/bash_completion.d/目录。这是一个脚本目录,Bash 将自动加载这些脚本以提供 shell 完成。

MAC zsh (12.4(

将此文本放入 .zshrc 中然后执行它。

在提示 % 时键入:

> echo 'autoload -Uz compinit && compinit' >> ~/.zshrc
> source ~/.zshrc
有多种

方法可以实现git auto-complete,我觉得下面的步骤很简单,对我有帮助。

步骤1:在Mac机器中创建文件(~/.git-completion.bash(并从 https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash 添加内容


> vi ~/.git-completion.bash
> copy-paste the content from linked shared above link
> Save the changes ( Press 'esc' button then press ':' then 'wq' then 'enter')

或使用简单的 curl 命令

> curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash

第 2 步:将文件~/.git-completion.bash~/.bash_profile链接

> vi ~/.bash_profile
> add following code in ~/.bash_profile
if [ -f ~/.git-completion.bash ]; then
  . ~/.git-completion.bash
fi
> Save the changes ( Press 'esc' button then press ':' then 'wq' then 'enter')

步骤 3:执行新添加的 git 完成命令

> ~/. bash_profile

步骤4: 现在您将能够看到git自动完成,只需键入git br并按tab现在您应该能够完成命令git branch或要完成的选项列表。

参考-https://apple.stackexchange.com/questions/55875/git-auto-complete-for-branches-at-the-command-line

最新更新