🧤

gitignore_globalで無視したいファイルはプロジェクトルートからパスを指定する

2021/03/28に公開

TL;DR

gitignore_globalで特定のファイルを無視したい時、ファイルはルートからのフルパスで指定せず、プロジェクトルートからのパスを指定する

以下のようなGitで管理されたプロジェクトhogeがあり、piyo.txtgitignore_globalで無視したい時

HOME
├.gitignore_global
└projects
 └hoge
  ├.git/
  ├.gitignore
  └fuga
   └piyo.txt

NG

/Users/user_name/projects/hoge/fuga/piyo.txt  # Macとか
~/projects/hoge/fuga/piyo.txt
  • ルートディレクトリからのフルパスで指定しない
  • ホームディレクトリからのパスで指定しない

OK

/fuga/piyo.txt
fuga/piyo.txt
piyo.txt
  • プロジェクトルートからのパスで指定する
  • ファイル名で指定する

その他

「gitignore_global 反映されない」などで検索していたが、git config --global core.excludesfile ~/.gitignore_globalしていないのでは?という記事ばかりで地味にハマった

参考

https://stackoverflow.com/questions/52389140/global-git-ignore-with-absolute-path

https://git-scm.com/book/ja/v2/Git-のカスタマイズ-Git-の設定

Discussion