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

Re: Excluding files from git-diff

From
Jeff King <peff@peff.net>
Date
Oct 18, 2008, 15:59 UTC
Message-ID
<20081018155912.GA20387@coredump.intra.peff.net>
In-Reply-To
<48F8BDA7.50901@pflanze.mine.nu>
On Fri, Oct 17, 2008 at 06:30:31PM +0200, Christian Jaeger wrote:
> For me, adding entries to that file does not make "git diff" or "gitk" or 
> even "git ls-files" ignore files matching the entries. Only "git ls-files 
> --others --exclude-from=.git/info/exclude" will exclude them. And "git 
> diff " and gitk don't seem to know the --exclude-from option.
What you are seeing is:
  - ls-files is plumbing, and does not do any exclusion by default. So
    you need to use the --exclude-from option, or more easily,
    --exclude-standard (which pulls in .git/info/excludes, .gitignore,
    and user-level excludes).
  - porcelain _does_ do exclusion. However, exclusion does not mean "if
    this file is tracked by git, don't include it in the diff." It
    merely means "if this file is untracked, pretend like it is not
    there." So a diff displayed by "git diff" isn't affected by
    exclusions anyway.
Show 5 quoted lines
> Is there a way to really invert the patterns given to "git diff" or  
> alike? I.e. instead of saying "git diff -- * .somedotfile  
> .someothernongitignoredotfile" one could just say something like "git  
> diff --invert-matches -- .gitignore"? And even better, could one  
> configure some such so that it has effect on all tools by default?

No, I don't think there is a way to do that currently. I would probably generate the file list with a shell snippet:

  git diff -- `git ls-files | grep -v .gitignore`

but obviously that is a lot more typing if this is something you are doing frequently.

-Peff
Previous: Christian JaegerNext: Christian Jaeger
Message 8 of 12 in “Excluding files from git-diff”
  1. Erik HahnOct 17, 2008
  2. Raphael ZimmererOct 17, 2008
  3. Johannes SchindelinOct 17, 2008
  4. Michael J GruberOct 17, 2008
  5. Christian JaegerOct 17, 2008
  6. Eric RaibleOct 17, 2008
  7. Christian JaegerOct 18, 2008
  8. Jeff KingOct 18, 2008
  9. Christian JaegerOct 18, 2008
  10. Jeff KingOct 18, 2008
  11. Jeff KingOct 18, 2008
  12. Anders MelchiorsenOct 17, 2008

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.