LoginSignup
6
2

More than 3 years have passed since last update.

環境依存のファイルを .gitignore に含めずに ignore する方法

Last updated at Posted at 2019-07-03

はじめに

複数名で開発している場合、人によって OS や エディタが異なるため、環境依存の一時ファイルなどを .gitignore に入れるのはよくありません。 Vim が生成するスワップファイル ( *.swp など ) や Mac が生成する .DS_Store など、他のメンバーには関係のない環境依存のファイルの ignore する方法を知ったので備忘録として残しておきます。

設定方法

Git の公式ドキュメントに記載されていたので引用します。

Which file to place a pattern in depends on how the pattern is meant to be used.
* 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_HOME is either not set or empty, $HOME/.config/git/ignore is used instead.

つまり、 $XDG_CONFIG_HOME の設定がある場合は $XDG_CONFIG_HOME/git/ignore 、ない場合は ~/.config/git/ignore に設定すれば良さそうです。

Vim のスワップファイルと Mac の .DS_Store を除外する場合は以下を配置すれば OK。スワップファイルは .swp とか .swo とか何種類かあるので ? でパターンマッチさせます。

~/.config/git/ignore
.DS_Store
*.sw?

以上。

関連記事

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2