例如,在一台新的ubuntu机器上,我刚刚运行了sudo apt-get git,在输入例如git check[tab]时没有完成。
我在http://git-scm.com/docs上没有找到任何东西,但IIRC完成是包含在这些天的git包中,我只需要在我的bashrc中正确的条目。
例如,在一台新的ubuntu机器上,我刚刚运行了sudo apt-get git,在输入例如git check[tab]时没有完成。
我在http://git-scm.com/docs上没有找到任何东西,但IIRC完成是包含在这些天的git包中,我只需要在我的bashrc中正确的条目。
当前回答
我也有同样的问题,遵循以下步骤:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
然后将以下行添加到.bash_profile(通常在您的主文件夹下)
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
来源:http://code-worrier.com/blog/autocomplete-git/
其他回答
在Linux上
在大多数发行版中,git完成脚本安装在/etc/bash_completion中。D /(或/usr/share/bash-completion/completion /git)安装git时,不需要去github。你只需要使用它-添加这一行到你的.bashrc:
source /etc/bash_completion.d/git
# or
source /usr/share/bash-completion/completions/git
在某些版本的Ubuntu中,默认情况下git自动完成可能会被破坏,通过运行这个命令重新安装应该可以修复它:
sudo apt-get install git-core bash-completion
在Mac
您可以使用Homebrew或MacPorts安装git完成。
家酿
if $BASH_VERSION > 4: brew install bash-completion@2(更新版本) 请特别注意您使用的bash版本,因为MacOS默认附带3.2.57(1)-release。
添加到.bash_profile:
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
对于旧版本的bash: brew安装bash-completion
添加到.bash_profile:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
MacPorts
Sudo端口安装git +bash_completion
然后把这个添加到你的.bash_profile中:
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
fi
更多信息在本指南:安装Bash git完成
注意,在所有情况下,您都需要创建一个新的shell(打开一个新的终端选项卡/窗口),以便更改生效。
Ubuntu 14.10
安装git-core和bash-completion
sudo apt-get install -y git-core bash-completion
对于当前会话使用情况 源/usr/share/bash-completion /完成/ git 在所有会议上都开着 Echo "source /usr/share/bash-completion/completion /git" >> ~/.bashrc
Mac M1
对于那些使用Mac M1环境的用户,我可以通过自制软件进行安装:
酿造安装bash-completion
然后添加到我的~/。Bash_profile或~/。Bashrc(不管你用什么):
[[ -r "/opt/homebrew/Cellar/bash-completion/1.3_3/etc/profile.d/bash_completion.sh" ]] && . "/opt/homebrew/Cellar/bash-completion/1.3_3/etc/profile.d/bash_completion.sh"
您可能需要更新版本号(1.3_3)。你只需要在那个目录中查找即可。我很想知道有没有更好的办法。
只需在~/.bashrc中这样做:
source /usr/share/bash-completion/completions/git
其他答案告诉你安装bash-completion,你不需要这样做,但如果你这样做,那么就不需要直接源完成。你只能做其中一个,不能两个都做。
一个更通用的解决方案是查询bash-completion项目推荐的系统位置:
source "$(pkg-config --variable=completionsdir bash-completion)"/git
Ubuntu
这里有一个美丽的答案。在Ubuntu 16.04上为我工作
窗户
Git Bash是允许自动完成的工具。不确定这是否是标准发行版的一部分,所以你可以发现这个链接也很有用。 顺便说一下,Git Bash允许使用Linux shell命令在windows上工作,这对于有GNU/Linux环境经验的人来说是一件很棒的事情。