tekitoumemo’s diary

思ったことを書くだけ。長文版Twitter

git 2.18から「Unknown option: --list-cmds ...」が起きたのでその対処法

macで開発してとgitコマンドをtabで入力補完してくれ他のでイライラしたので、入力補完をいれてみました(今更)。まぁ、Homebrew経由でインストールすればこんなことにならないのでちゃんとやりましょう。

僕の場合はgitが以下のインストーラーで、bash-completionがHomebrewで入れたのでちょっとめんどくさいことになったのでその備忘録として。だから参考にしないでください。
Git

Homebrewをインストール

brew.sh
Macで入れてない人いないと思うんで上記のサイトのコマンドで適当にやってください。

bash-completionのインストール

brew install bash-completion

「/usr/local/etc/bash_completion.d/」にコマンド補完用のシンボリックリンクが出来ていると思います。僕の場合はgit-completion.bashとかが入ってますが気にしないでください。
f:id:tekitoumemo:20180714193042p:plain

bash_completion.dに以下を書く

if [ -f $(brew --prefix)/etc/bash_completion ]; then
  source $(brew --prefix)/etc/bash_completion
fi

gitをHomebrewでインストールしてないのでgit-completion.bashとgit-prompt.shがありません。
なのでwgetで入れます(そもそもwgetすらない)。

brew install wget
cd /usr/local/etc/bash_completion.d/
wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -O git-completion.bash
wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -O git-prompt.sh

cd
source .bash_profile

でgit statusって打とうとしてタブ入力したら以下のエラー

git staUnknown option: --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--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>]
           <command> [<args>]

これは2.18から「--list-cmds」が追加されたようで、git-completion.bashは2.18、gitは2.16.3だったのでgitでオプションがないよ!って言われてるみたい

git-completion.bashのバージョンを下げるかgitをあげるかどちらかなんですが、下げる意味がないので私はバージョンをあげて対処しました。Homebrewでインストールしてないのでここインストーラーから入れました。

まじで誰も得しない記事だなこれは!