48

I have configured numerous .gitignore files to filter out many different unwanted files from a set of about 6,000 untracked files. I want to do git add . when I've got my filtered list looking the way I want it.

But, then I want to disable the .gitignore filters temporarily to see what got left behind, and make sure there was nothing important accidentally filtered.

I know that git-clean includes an option to ignore .gitignore files. Is there a similar option for git-status?

I could go through and delete all the .gitignore files, do the check, then restore them, but it seems there should be an easier way?

nalply
  • 20,652
  • 12
  • 75
  • 93
davidA
  • 10,282
  • 8
  • 54
  • 76

3 Answers3

57

This option --ignored does the trick:

git status --ignored



(Update 1) I found the --ignored option alone doesn't work in certain git installations, perhaps it's a git bug. In those cases, an additional -s works for me:

git status -s --ignored

(Update 2) One user reported --ignored option is not supported in git version 1.7.0.4. My git version is 1.7.6. Another version 1.7.5.1 is the one that requires -s. You may try

git status -h

to see if --ignored is supported.

Penghe Geng
  • 10,573
  • 3
  • 27
  • 39
  • +1 This must be accepted answer!!! man git status does not document `--ignored` option. and btw, `--ignored` is supported in git 1.8.4 – mvp Sep 27 '13 at 17:33
  • Hi. This is the one I've found to be most functional. I'm especially pleased that it confirms the exclusion for Windows Junction file-types with Dart. I'd also add the further pre-ADD check if you like to show what will be included: "***git add* -A -n -v .**". – will May 01 '14 at 08:45
40

Try using git ls-files --other - it should list all files that git doesn't know about; i.e. those files that aren't in the repository and aren't ignored by .gitignore.

You can also use git ls-files --ignored --exclude-standard to see what files git is explicitly ignoring.

Blair Holloway
  • 14,231
  • 1
  • 27
  • 28
  • 1
    Thank you for your reply - it seems that 'git-ls-files --other' also lists ignored files. Does that second command work if you're using distributed .gitignore files? E.g. separate .gitignore files located at different levels of the subdirectory tree? Would you have to specify --exclude-from=<> for each .gitignore in the tree? That would require a crafty find command methinks. – davidA Jun 08 '10 at 04:05
  • 1
    Apparently you can use --exclude-standard to read the `.gitignore` file from each subdirectory. See here: http://stackoverflow.com/questions/466764/show-ignored-files-in-git I'll update my answer to accomodate. – Blair Holloway Jun 08 '10 at 04:16
  • --exclude-standard is useful - thank you. – davidA Jun 09 '10 at 04:33
  • Thanks! In the hope of affecting indexing, I want to mention that this is what I wanted when I searched for temporarily override gitignore. – sage Aug 16 '13 at 23:35
  • `--other` lists unversioned files, and ignored unversioned files, `--ignored --exclude-standard` ignored versioned. Am I missing something? – x-yuri Dec 31 '19 at 21:42
3

git clean -dXn

See: Git command to show which specific files are ignored by .gitignore

In fact this question seems to be a duplicate!

Community
  • 1
  • 1
nalply
  • 20,652
  • 12
  • 75
  • 93
  • No, they're different. This question is specifically asking how to do it with `git-status`. – iconoclast Aug 31 '12 at 17:48
  • 2
    Formally they might be different. But you are not very helpful if you concentrate on the form of the question only and ignore the rationales and motivations behind the question. – nalply Sep 01 '12 at 11:10
  • Made it community wiki, because it's not my answer, just a link to someone else's answer. – nalply Apr 23 '13 at 21:18