How to configure git bash command line completion?

前端 未结 12 1455
猫巷女王i
猫巷女王i 2020-11-28 18:50

E.g. on a fresh ubuntu machine, I\'ve just run sudo apt-get git, and there\'s no completion when typing e.g. git check[tab].

I didn\'t find

12条回答
  •  没有蜡笔的小新
    2020-11-28 19:33

    Most of the instructions you see will tell you to download

    https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash

    and source that in your bash startup script like .bashrc.

    But there is a problem with that, because it is referencing the master branch, which is the latest version of git-completion.bash. The problem is that sometimes it will break because it is not compatible with the version of git you've installed.

    In fact, right now that will break because the master branch's git-completion.bash has new features that requires git v2.18, which none of the package managers and installers have updated to yet. You'll get an error unknown option: --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config

    So the safest solution is to reference the version/tag that matches the git you've installed. For example:

    https://raw.githubusercontent.com/git/git/v2.17.1/contrib/completion/git-completion.bash

    Note that it has a v2.17. in the URL instead of master. And then, of course, make sure to source that in the bash startup script.

提交回复
热议问题