Gitの小ネタおれおれAdvent Calendar 2022 – 04 日目

といっても Git 自体にはそういう設定がなくて 2 段階になります。

  1. Git で、出力に使うコマンドの設定をする
  2. 表示に使うコマンドで、タブ幅を設定する

タブ幅の設定

具体的にはこう。

$ git config --global core.pager "less -x2"

2 がタブ幅です。

core.pager

Git の各種コマンドで利用するテキストビューワーの設定。

less -x2

less で表示するとき -x オプションでタブ幅を指定できます。

man less より:

-xn,… or –tabs=n,…

Sets tab stops. If only one n is specified, tab stops are set at multiples of n. If multiple values separated by commas are specified, tab stops are set at those posi‐ tions, and then continue with the same spacing as the last two. For example, -x9,17 will set tabs at positions 9, 17, 25, 33, etc. The default for n is 8.

n は任意の数値です。2 文字なら -x2 、8 文字なら -x8 に。