Git diff in summary?

git log --stat will show the amount each file was changed.

git whatchanged gives some detail into the files that were modified.

git diff --stat <sha1> <sha2> gives the files and the amount of changes between two commits.

git diff --stat <branch> to compare to another branch (e.g. master)


Is there a way to use commands like git diff to get similar output?

With Git 2.17 (Q2 2018), there actually is, with a result a bit more complete than git diff -stat:

"git diff" and friends learned "--compact-summary" that shows the information usually given with the "--summary" option on the same line as the diffstat output of the "--stat" option (which saves vertical space and keeps info on a single path at the same place).

See commit ddf88fa (24 Feb 2018), and commit c905cbc (01 Feb 2018) by Nguyễn Thái Ngọc Duy (pclouds).
(Merged by Junio C Hamano -- gitster -- in commit 868f7d2, 14 Mar 2018)

diff: add --compact-summary

Certain information is currently shown with --summary, but when used in combination with --stat it's a bit hard to read since info of the same file is in two places (--stat and --summary).

On top of that, commits that add or remove files double the number of display lines, which could be a lot if you add or remove a lot of files.

--compact-summary embeds most of --summary back in --stat in the little space between the file name part and the graph line, e.g. with commit 0433d53:

Documentation/merge-config.txt         |  4 +
builtin/merge.c                        |  2 +
...-pull-verify-signatures.sh (new +x) | 81 ++++++++++++++
t/t7612-merge-verify-signatures.sh     | 45 ++++++++
4 files changed, 132 insertions(+)

It helps both condensing information and saving some text space.

What's new in diffstat is:

  • A new 0644 file is shown as (new)
  • A new 0755 file is shown as (new +x)
  • A new symlink is shown as (new +l)
  • A deleted file is shown as (gone)
  • A mode change adding executable bit is shown as (mode +x)
  • A mode change removing it is shown as (mode -x)

Note that --compact-summary does not contain all the information --summary provides. Rewrite percentage is not shown but it could be added later, like R50% or C20%.


The summary will be even more concise with Git 2.29 (Q4 2020), since "git diff --stat -w(man) showed 0-line changes for paths whose changes were only whitespaces, which was not intuitive.

Such paths are now omitted from the stat output.

See commit 1cf3d5d (20 Aug 2020) by Matthew Rogers (ROGERSM94).
(Merged by Junio C Hamano -- gitster -- in commit b58e47a, 03 Sep 2020)

diff: teach --stat to ignore uninteresting modifications

Signed-off-by: Matthew Rogers

When options such as --ignore-space-change are in use, files with modifications can have no interesting textual changes worth showing.
In such cases, "git diff --stat"(man) shows 0 lines of additions and deletions. Teach "git diff --stat" not to show such a path in its output, which would be more natural.

However, we don't want to prevent the display of all files that have 0 effective diffs since they could be the result of a rename, permission change, or other similar operation that may still be of interest so we special case additions and deletions as they are always interesting.


git diff is indeed the command you seek. In particular you want

git diff --stat

Other similar reports are available using

git diff --numstat
git diff --shortstat
git diff --dirstat
git diff --name-status

Tags:

Git