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

Re Behavior of git log --diff-filter=d

From
K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Date
Jul 3, 2025, 13:42 UTC
Message-ID
<20250703134220.31638-1-jayatheerthkulkarni2005@gmail.com>
In-Reply-To
<64308d3f-281b-49a3-bc10-57878903bf4c@gmail.com>
Hi Eric,
Nice question

Yes, this is expected behavior You're seeing a difference because

--diff-filter=d tells Git to exclude commits that have deleted files in their diffs. However, this filter only applies if there is a diff to filter.

In other words, if you run git log --format="%H" --diff-filter=d, Git doesn't show any output unless the diff logic is actually invoked. But --format="%H" alone does not invoke diff generation... so --diff-filter silently does nothing.

When you add --stat or --name-only, you're explicitly telling Git: "Please compute the diff".

Now Git has something to filter, and it applies --diff-filter=d to exclude those diffs that involve deletions.

If you want to exclude deletion commits and get just commit hashes This is something I think should work probably set this up with an alias if you use this many times

git log --format="%H" --diff-filter=d --name-only | grep -v '^$'
This should work just fine...

Or perhaps if you wanna tinker more git log --format="%H" --diff-filter=d --stat | grep -B1 -v "delete mode"

But if you're just trying to filter commits by file change type and want to see only those hashes where a deleted file is not present, you'll need some way to trigger the diff even if you discard the output later.

Hope that helps :)
Thank you,
- Jayatheerth
Previous: Eric SalemNext: Jeff King
Message 2 of 9 in “Behavior of git log --diff-filter=d”
  1. Eric SalemJul 2, 2025
  2. Re Behavior of git log --diff-filter=dK Jayatheerth, Jul 3, 2025
  3. Jeff KingJul 3, 2025
  4. Eric SalemJul 3, 2025
  5. Jeff KingJul 3, 2025
  6. setup_revisions(): turn on diffs for all-negative diff filterJeff King, Jul 3, 2025
  7. Eric SalemJul 3, 2025
  8. Karthik NayakJul 4, 2025
  9. Junio C HamanoJul 7, 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.