Filter git diff by type of change

published on January 02, 2020.

Yesterday I was looking at a rather large diff, but for the type of change I was after, I wanted to look only at the newly added files. Turns out, git diff has a filtering option with --diff-filter.

The possible values for the --diff-filter are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), type changed (T), Unmerged (U), Unknown (X), and some kind of a Broken (B) file(?).

Running git diff --diff-filter=A will show the diff only for the added files.

These filtering options can also be provided with lowercase, in which case it will behave as an exclude filter. git diff --diff-filter=a will show the diff for all files, except for added ones.

Happy hackin’ and a happy new year!

Versions used for examples: git 2.17.
Tags: git, diff, filter.
Categories: Development, Software.

Thanks for reading! I would like to help you make your web application better, so let's talk.

Robert Basic

Robert Basic

Software developer making web applications better.

Let's work together!

I would like to help you make your web application better.

Robert Basic © 2008 — 2020
Get the feed