たとえば以下のような構成のプロジェクトがある場合。 (git init済み)
$ tree sample_project/ sample_project/ |-- index.html |-- log -> /var/log/httpd/ |-- sample_dir | `-- test.php `-- sample.php
何も設定していない場合のgit statusコマンドでは以下の用に出力される。
$ git status => On branch master Initial commit Untracked files: (use "git add..." to include in what will be committed) index.html log sample.php sample_dir/
treeコマンドの結果で分かる通り、logファイルはシンボリックリンクである。 ログとかtmpファイル等の可変的なものをバージョン管理で扱うと色々面倒なので除外しようとした時にgitignoreを書くんだけども、 普通のディレクトリを除外する時は以下のように書けば除外出来る。
$ vi .gitignore
/sample_dir/ # もしくは /sample_dir
$ git status => On branch master Initial commit Untracked files: (use "git add..." to include in what will be committed) .gitignore index.html log sample.php
sample_dirが表示されていないのが確認できる。 ただしシンボリックリンクを除外する場合は以下の書き方でなければ除外できない。
$ vi .gitignore
/log
$ git status => On branch master Initial commit Untracked files: (use "git add..." to include in what will be committed) .gitignore index.html sample.php sample_dir/
シンボリックリンクはあくまで対象のディレクトリのパスが書かれているだけの「ファイル」なのでこうなる模様。
ちなみに
/log/と書いた場合にgit statusを見てみると
$ vi .gitignore
/log/
$ git status => On branch master Initial commit Untracked files: (use "git add..." to include in what will be committed) .gitignore index.html log sample.php sample_dir/
出てきちゃう。