Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Notes: </p> <ul> <li><a href="https://stackoverflow.com/users/814145/xiaobai">xiaobai</a>'s <a href="https://stackoverflow.com/a/12080920/6309">answer</a> is simpler (git1.7.6+): <strong><code>git status --ignored</code></strong><br> (as detailed in "<a href="https://stackoverflow.com/a/12080857/6309">Is there a way to tell git-status to ignore the effects of <code>.gitignore</code> files?</a>")</li> <li><a href="https://stackoverflow.com/users/242933/mattdipasquale">MattDiPasquale</a>'s <a href="https://stackoverflow.com/questions/466764/show-ignored-files-in-git/2196755#2196755">answer</a> (to be upvoted) <strong><code>git clean -ndX</code></strong> works on older gits, displaying a <em>preview</em> of what ignored files could be removed (without removing anything)</li> </ul> <hr> <p>Also interesting (mentioned in <a href="https://stackoverflow.com/users/465546/qwertymk">qwertymk</a>'s <a href="https://stackoverflow.com/a/26580088/6309">answer</a>), you can also use the <a href="http://git-scm.com/docs/git-check-ignore" rel="noreferrer"><strong><code>git check-ignore -v</code></strong></a> command, at least on Unix (<strong>doesn't work</strong> in a CMD <strong>Windows</strong> session)</p> <pre><code>git check-ignore * git check-ignore -v * </code></pre> <p>The second one displays the actual rule of the <code>.gitignore</code> which makes a file to be ignored in your git repo.<br> On Unix, using "<a href="https://stackoverflow.com/questions/1690809/what-expands-to-all-files-in-current-directory-recursively">What expands to all files in current directory recursively?</a>" and a bash4+:</p> <pre><code>git check-ignore **/* </code></pre> <p>(or a <code>find -exec</code> command)</p> <hr> <p>Original answer 42009)</p> <pre><code>git ls-files -i </code></pre> <p>should work, except <a href="http://www.mail-archive.com/git@vger.kernel.org/msg03245.html" rel="noreferrer">its source code</a> indicates:</p> <pre><code>if (show_ignored &amp;&amp; !exc_given) { fprintf(stderr, "%s: --ignored needs some exclude pattern\n", argv[0]); </code></pre> <p><code>exc_given</code> ?</p> <p>It turns out it need one more parameter after the <code>-i</code> to actually list anything:</p> <p>Try:</p> <pre><code>git ls-files -i --exclude-from=[Path_To_Your_Global].gitignore </code></pre> <p>(but that would only list your <em>cached</em> (non-ignored) object, with a filter, so that is not quite what you want)</p> <hr> <p>Example:</p> <pre><code>$ cat .git/ignore # ignore objects and archives, anywhere in the tree. *.[oa] $ cat Documentation/.gitignore # ignore generated html files, *.html # except foo.html which is maintained by hand !foo.html $ git ls-files --ignored \ --exclude='Documentation/*.[0-9]' \ --exclude-from=.git/ignore \ --exclude-per-directory=.gitignore </code></pre> <hr> <p>Actually, in my 'gitignore' file (called 'exclude'), I find a command line that could help you:</p> <pre><code>F:\prog\git\test\.git\info&gt;type exclude # git ls-files --others --exclude-from=.git/info/exclude # Lines that start with '#' are comments. # For a project mostly in C, the following would be a good set of # exclude patterns (uncomment them if you want to use them): # *.[oa] # *~ </code></pre> <p>So....</p> <pre><code>git ls-files --others --ignored --exclude-from=.git/info/exclude git ls-files -o -i --exclude-from=.git/info/exclude git ls-files --others --ignored --exclude-standard git ls-files -o -i --exclude-standard </code></pre> <p>should do the trick.</p> <p>As mentioned in the <a href="http://www.kernel.org/pub/software/scm/git/docs/git-ls-files.html" rel="noreferrer">ls-files man page</a>, <code>--others</code> is the important part, in order to show you non-cached, non-committed, normally-ignored files.</p> <p><code>--exclude_standard</code> is not just a shortcut, but a way to include <em>all</em> standard "ignored patterns" settings.</p> <blockquote> <p><code>exclude-standard</code><br> Add the standard git exclusions: <code>.git/info/exclude</code>, <code>.gitignore</code> in each directory, and the <code>user's global exclusion file</code>.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload