日々前進するトンカツ男

日々前進するトンカツ男

ここはトン・カツ男の部屋です🐽

gitignore公式リファレンスの要点メモ

gitignoreってどうやって書くんだっけってよくなるから、今一度ちゃんと公式リファレンスを参照して今後使いそうな・参考になりそうな部分だけ抽出したカンペを作ります。

参照元

Git - gitignore Documentation

 

では早速...

Files already tracked by Git are not affected

すでにgitの管理下にあるファイルはgitignoreの影響を受けない。gitの管理下にあるというのは、git add以上の操作をしているファイルが該当する。

 

To stop tracking a file that is currently tracked, use git rm --cached.

すでにgit管理下にあるファイルを管理しないようにしたい場合はgit rm --cached <target>とするとよい。おすすめは、git rm --cached .で一旦全部管理外から外し、git add .とすることで再度.gitignoreにマッチしないものを再度全部管理下に戻す、です。-rは再起的に削除するためのオプション、-fは強制的に削除するためのオプション。

 

within one level of precedence, the last matching pattern decides the outcome

複数のパターンにマッチする場合には、後から記述されているパターンが優先される後勝ち方式。

 

Patterns read from a .gitignore file in the same directory as the path, or in any parent directory (up to the top-level of the working tree), with patterns in the higher level files being overridden by those in lower level files down to the directory containing the file. 

深い階層にある.gitignoreが優先される

 

These patterns match relative to the location of the .gitignore file

.gitignoreを基準にしたパスで書く

 

An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again.

"!"をパターンの頭につけてパターンの否定ができる

 

If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself. Otherwise the pattern may also match at any level below the .gitignore level.

先頭に"/"を付けるとその.gitignoreが存在する階層でパターンにマッチするものを探す。頭に"/"がない場合には深い階層を再帰的に探索する。

 

If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself. Otherwise the pattern may also match at any level below the .gitignore level.

先頭または中間にスラッシュが存在する場合は記述されている.gitignoreと同階層のみを探索する

 

If there is a separator at the end of the pattern then the pattern will only match directories, otherwise the pattern can match both files and directories.

末尾スラッシュがあればディレクトリのみマッチするが、ない場合はファイルおよびディレクトリのどちらもマッチする。

 

An asterisk "*" matches anything except a slash. The character "?" matches any one character except "/". The range notation, e.g. [a-zA-Z], can be used to match one of the characters in a range. See fnmatch(3) and the FNM_PATHNAME flag for a more detailed description.

ワイルドカードでパターンを記述することができる。"*"でスラッシュ以外のなんでもマッチ、"?"でスラッシュ以外の一文字にマッチする。

 

A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.

アスタリスク二つはスラッシュで一つ以上の任意のディレクトリに相当する

 

終わり

こんなところですかね。迷ったらここを見ればいいように自分で活用しながらブラッシュアップいきます。