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