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

Re: git-diff: --ignore-matching-lines has no effect on the output when --name-only is used

From
Jeff King <peff@peff.net>
Date
Jul 25, 2025, 11:11 UTC
Message-ID
<20250725111139.GB3014187@coredump.intra.peff.net>
In-Reply-To
<87ldocsnew.fsf@arnes.space>
On Fri, Jul 25, 2025 at 10:08:23AM +0200, hi@arnes.space wrote:
Show 12 quoted lines
> i understand, and i get why that's useful from a performance
> perspective. but i think i'm arguing at a different level.
> 
> i'm saying: `--name-only` can change whether a file appears in `git
> diff`'s output or not. that is surprising, because the documentation
> mentions nothing about this, nor does the flag itself sound like it
> would.
> 
> my argument is that the non-buggy behavior would be to make
> `--name-only` more consistent with the rest of `git diff`, because it
> would be less surprising. the fact that `git diff` does not look at file
> contents when the flag is given to me is just an implementation detail. 

Yeah, that line of thinking makes sense to me. It's an optimization not to look at the file contents when we do not need to. But if you've asked to do a more specific content-level comparison, then we could do that.

I think Junio's response earlier in the thread discusses this, and how we already respect "-w" for "--quiet".

I'm not sure I agree with this part that he wrote, though:
Show 8 quoted lines
> It is just --raw, --name-only, --name-status, and --checkdiff output
> formats that deliberately ignore content based ignore mechanisms.
> 
> And I do not think it would be a good change to have them follow
> "ignore" bits.  When asked "has this path been modified?"  "what are
> the before and after blob object names?" etc., it does not make sense
> for the answer to be different depending on the presense of -w or
> --ignore-matching options.

I can see how it gets weird when you ask for --raw, but the object ids we show do not necessarily reflect the content we actually compared. But it is even weirder to me that something like:

  git init
  echo 'foo' >file
  git add . && git commit -m base
  echo 'foo ' >file
  git diff -w --stat -p --name-only

will show "file" in the name-only list, but not in the accompanying stat or patch! If the user has bothered to ask for a whitespace-only diff, then it feels to me like the least-bad thing is to apply that consistently to all output.

I do wonder if changing it at this point would somehow break somebody's workflow or have unexpected fallout, though.

-Peff
Previous: hi@arnes.spaceNext: Junio C Hamano
Message 11 of 35 in “git-diff: --ignore-matching-lines has no effect on the output when --name-only is used”
  1. hi@arnes.spaceJul 23, 2025
  2. Lidong YanJul 23, 2025
  3. Junio C HamanoJul 23, 2025
  4. Lidong YanJul 24, 2025
  5. Eric SunshineJul 24, 2025
  6. Lidong YanJul 24, 2025
  7. hi@arnes.spaceJul 25, 2025
  8. hi@arnes.spaceJul 25, 2025
  9. Lidong YanJul 25, 2025
  10. hi@arnes.spaceJul 25, 2025
  11. Jeff KingJul 25, 2025
  12. Junio C HamanoJul 25, 2025
  13. diff: ensure consistent diff behavior with -I<regex> across output formatsLidong Yan, Jul 29, 2025
  14. Junio C HamanoJul 30, 2025
  15. Jeff KingAug 2, 2025
  16. Lidong YanAug 3, 2025
  17. Junio C HamanoAug 3, 2025
  18. Junio C HamanoAug 4, 2025
  19. Jeff KingAug 4, 2025
  20. diff: ensure consistent diff behavior with -I<regex> across output formatsLidong Yan, Aug 3, 2025
  21. Junio C HamanoAug 4, 2025
  22. Lidong YanAug 4, 2025
  23. Junio C HamanoAug 4, 2025
  24. Lidong YanAug 5, 2025
  25. Junio C HamanoAug 5, 2025
  26. diff: ensure consistent diff behavior with ignore optionsLidong Yan, Aug 6, 2025
  27. Junio C HamanoAug 6, 2025
  28. Lidong YanAug 7, 2025
  29. Junio C HamanoAug 6, 2025
  30. Lidong YanAug 7, 2025
  31. diff: ensure consistent diff behavior with ignore optionsLidong Yan, Aug 7, 2025
  32. Junio C HamanoAug 7, 2025
  33. Lidong YanAug 8, 2025
  34. diff: ensure consistent diff behavior with ignore optionsLidong Yan, Aug 8, 2025
  35. Johannes SchindelinOct 16, 2025

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.