git安装好后发现命令不能自动补全于是搜了很多方法,先按博客里面的方法试了下:
1.下载配置文件 git clone git://git.kernel.org/pub/scm/git/git.git
2.cp git/contrib/completion/git-completion.bash ~/.git-completion.bash
3.在.bashrc中添加 source ~/.git-completion.bash
但是在执行第一步的时候就遇到了问题,一直报错,尝试改了DNS地址也还是不行,于是就手动去官网下载下来然后复制到根目录下,接着执行第三步然后重启终端,尝试用tab键补齐命令,但是还是不成功,显示如下
$ git commi <tab>
Unknown option: --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[-c name=value] [--help]
<command> [<args>]
git: 'commi' is not a git command. See 'git --help'.
Did you mean one of these?
commit
config
在https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration中发现要将help.autocorrect 设为1才会自动更正
git config --global help.autocorrect 1
然而设置好后还是出现和之前一样的情况,接着在网上找办法,最终在https://github.com/yszheda/wiki/wiki/git-tips#bash_autocomplete_Unknown_option_listcmdslistmainporcelainothersnohelpersaliaslistcompleteconfig中找到了解决办法
source /etc/bash_completion.d/git
# or
source /usr/share/bash-completion/completions/git
输入命令行再次尝试就可以了.