LoginSignup
74
65

More than 5 years have passed since last update.

Gitでignoreされてるか確認する

Last updated at Posted at 2017-10-25

.gitignore書いてみたけど「本当にignoreされるのかわからない!」と悩むケースがあったんで、メモ書き程度に。(翻訳)【GitHub公式】Gitコマンドチートシートをみて、「あーなるほどな!」と思って書きました。

開発環境

  • Mac
  • iTerm2
  • zsh

.gitignoreを書いてみる

以下のようなディレクトリにいる状況で、.gitignorehogeという拡張子のファイルをすべて無視するように記述します

$ tree

├── test.hoge
├── test.text
└── dir
    ├── test2.hoge
    └── test2.text
--- #.gitignore ---

*.hoge

しかしgit addする前にgit statusをしてもdirの中がどうなっているのかわかりません
(addした後なら当然わかりますから、とりあえずgit addするのは1つの手)

$ git status

Untracked files:
    .gitignore
    test.text
    dir/

ignoreされてるか確認

git status --ignored

これでいけるらしい...... がgit addする前では、dirのなかのtest2.hogeIgnored filesとして表示されない
git addした後ならきちんと表示される)

$ git status --ignored

Untracked files:
    .gitignore
    test.text
    dir/

Ignored files:
    test.hoge

git ls-files --other --ignored --exclude-standard

そこで使うのがgit ls-files --other --ignored --exclude-standardです
git addの前でもどのファイルが無視されているのかがわかります

$ git ls-files --other --ignored --exclude-standard

test.hoge
dir/test2.hoge

きちんと*.hogeが無視されているのが確認できました!

参考

74
65
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
74
65