gitshellfile-diffs

Suppressing diffs for deleted files in git


I want to get a quick overview of the local changes in my repository, but I don't want a diff that shows deleted files, since every single line is a minus.

Basically, I want something like 'git diff HEAD <list of modified files only>'. In an ideal world, it would be preceded by the list of deleted and added files, but not show the diffs within them.

I was most of the way through writing a utility that does this:

git diff HEAD `git status | grep modified | cut -d : -f 2`

when I wondered if there was some git-y way to do it instead. Is there a flag I'm missing? I'd love to preserve the color output, too.


Solution

  • In Git versions 1.8.5 and newer, you can do this using the --diff-filter option and specifying "d" (lowercase) to tell it to exclude deleted files.

    $ git diff --diff-filter=d
    

    In Git versions older than 1.8.5, you can do this with the --diff-filter option and specifying all but the "D" (deleted) criteria:

    $ git diff --diff-filter=ACMRTUXB
    

    For reference the git documentation of version 2.43.2 says:

    --diff-filter=[(A|C|D|M|R|T|U|X|B)…​[*]]

    Select only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, …​) changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B). Any combination of the filter characters (including none) can be used. When * (All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing is selected.

    Also, these upper-case letters can be downcased to exclude. E.g. --diff-filter=ad excludes added and deleted paths.

    Note that not all diffs can feature all types. For instance, copied and renamed entries cannot appear if detection for those types is disabled.