7

I have been using git from past few months and I like git. I was wondering if there is a command which can show list of ignored files in a project.

I tried this git status --ignored from root directory of the project but it doesn't seem to be sufficient.

Simone Carletti
  • 168,884
  • 43
  • 353
  • 360
Sangam Gupta
  • 111
  • 1
  • 5

3 Answers3

7

You can use the clean command with the option:

-n, --dry-run - Don't actually remove anything, just show what would be done

git clean -ndX 

In this way git will list all the files that would be cleaned without doing anything, and you get a list of ignored files.

Atropo
  • 11,652
  • 4
  • 45
  • 58
  • @SangamGupta you're welcome,. If you find my answer useful please accept it and/or upvote, thanks. – Atropo Dec 18 '13 at 09:28
3
  1. find -type f | git check-ignore --stdin gives all files ignored in whole repo (and if you have some in .git that fit, it will report them too).
  2. git ls-files --exclude-standard --ignored --others - gives ignored file per current directory (not whole repository).

Both solutions honor not just top-level .gitignore file, but also global one, .git/info/exclude and local (in lower-level dirs) .gitignores

  • Interesting commands. +1 By the way it seems that these two commands don't output the same files, if there are symlinks among ignored paths. But `find -xtype f | git check-ignore --stdin` seems to do the trick. – ErikMD Jan 05 '18 at 21:39
  • An interesting case @ErikMD, thanks for it. `find -type` matches against the file, not symlink so that fits. You may also try `-type l` if you would like to target links specifically. – LAFK says Reinstate Monica Jan 06 '18 at 19:25
1

You can edit the .gitignore file found in the same directory as your .git folder if you are looking for a list of files to ignore (listed on each line as regular expressions).

Example:

cat .gitignore

might show:

^build$ 
^build[/].
*-objs/ 
.project
*~
Damien
  • 1,131
  • 2
  • 18
  • 30
  • 1
    cat .gitignore command will simply display the content of .gitignore file, I am looking for some cleaner way using git command. – Sangam Gupta Dec 18 '13 at 09:24