git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: refining .gitignores

From
Alex Riesen <raa.lkml@gmail.com>
Date
Nov 15, 2007, 19:26 UTC
Message-ID
<20071115192654.GA3552@steel.home>
In-Reply-To
<807ikj3fge.fsf@tiny.isode.net>
Bruce Stephens, Thu, Nov 15, 2007 12:39:45 +0100:
Show 19 quoted lines
> Alex Riesen <raa.lkml@gmail.com> writes:
> > Bruce Stephens, Wed, Nov 14, 2007 23:36:06 +0100:
> >> How do I get a list of files (in HEAD, say) that would be ignored by
> >> the .gitignore files (and the other usual settings)?
> >> 
> >> It feels like something like this ought to work:
> >> 
> >>      git ls-files -z | xargs -0 git ls-files --ignored
> >> 
> >> But listing its arguments that are ignored by .gitignore (etc.)
> >> doesn't seem to be what "git ls-files --ignored" does.  Or at least,
> >> not quite as straightforwardly as that.
> >
> > git ls-files --exclude-per-directory=.gitignore -X .git/info/exclude -i -o
> 
> That doesn't seem to work.
> 
> For example, if I add '*.c' to .gitignores in git.git, I can't seem to
> get that command to display any .c files.

.gitignore? Without "s"? Maybe your .c files are already added to index? Otherwise you have to use the second form. It shows known-to-Git ignored files.

> Run on its own, it displays lots of files, but no .c files.  Run with
> an argument (such as builtin-add.c), it displays nothing.
because the *are* in the index. "-o" means "others", as in "not Git".
Show 8 quoted lines
> >> The motivation is (obviously) that I fear some of the .gitignore
> >> patterns are too broad, and a reasonable check is that none of the
> >> files that are already committed would be caught by the patterns.
> >
> > git ls-files --exclude-per-directory=.gitignore -X .git/info/exclude -i
> 
> That also doesn't seem to do quite what I want, and probably in the
> same way. ...
It shows ignored files from the "known-to-Git" fileset.
Previous: Bruce StephensNext: Bruce Stephens
Message 4 of 9 in “refining .gitignores”
  1. Bruce StephensNov 14, 2007
  2. Alex RiesenNov 14, 2007
  3. Bruce StephensNov 15, 2007
  4. Alex RiesenNov 15, 2007
  5. Bruce StephensNov 15, 2007
  6. Linus TorvaldsNov 15, 2007
  7. Bruce StephensNov 15, 2007
  8. Alex RiesenNov 15, 2007
  9. Linus TorvaldsNov 15, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.