よく .gitignore_global を使っていたのですがスタンダードな方法が変わったようです。毎回忘れて調べるので自分用にメモします。
TL;DR
# 今まで
echo foobar > ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
# これから
echo foobar > ~/.config/git/ignore
なぜ?
もともと core.excludesfile に任意のファイルを登録すれば良いらしく ".gitignore_global" というファイル名が慣習的に使われている、ということです。PC を替えるといそいそとファイル作ってましたが別に何でも良かったんですね。
さらに git のバージョンアップにより core.excludesfile にわざわざ登録しなくても良くなりました。$XDG_CONFIG_HOME/git/ignore が .gitignore_global に変わるスタンダードです。
https://git-scm.com/docs/gitignore
Patterns which a user wants Git to ignore in all situations (e.g., backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile in the user’s ~/.gitconfig. Its default value is
$XDG_CONFIG_HOME/git/ignore. If$XDG_CONFIG_HOMEis either not set or empty,$HOME/.config/git/ignoreis used instead.
Git は「XDG Base Directory」に準拠しています。これは設定ファイルやデータなど種類ごとのベースディレクトリを定めるものです。
https://specifications.freedesktop.org/basedir-spec/latest/
~/.config/ # 設定ファイル
~/.cache/ # キャッシュ
~/.local/share/ # 一時ファイル
ベースディレクトリは環境変数で変更できます。$XDG_CONFIG_HOME は設定ファイルのディレクトリの場所を示します。
printenv |grep XDG_CONFIG_HOME
>
git の説明では環境変数が空ならデフォルトの ~/.config/git/ignore が適用されると書かれています。
touch foobarbaz.json
git status
> ...
> Untracked files:
> (use "git add <file>..." to include in what will be committed)
> foobarbaz.json
# 除外ファイルに追加
echo foobarbaz.json >> ~/.config/git/ignore
git status
> ...
> nothing to commit, working tree clean
...おお、ちゃんと効いてますね!
- Git の除外ファイルは
$XDG_CONFIG_HOME/git/ignoreに書く - デフォルトだから
core.excludesfileしなくて良い
まとめるとこういう事みたいです。