diffstat
Summarize diff output statistics
TLDR
Display changes in a histogram
Display inserted, deleted and modified changes as a table
SYNOPSIS
diffstat [options] [file...]
Most commonly used by piping diff output: diff [options] | diffstat [options]
PARAMETERS
-c
Show cumulative line counts for additions and deletions across all files processed.
-f
Specify the output format. Common formats include 'brief' (default: filename, changed lines, histogram) or 'total' (just total lines changed).
-g
Always show the graphical histogram, even if other options might suppress it (often default behavior).
-h
Display a help message with command usage and options, then exit.
-l
Do not truncate long filenames in the output, showing full paths.
-n
Do not show the graphical histogram; print numeric totals only for additions, deletions, and changed lines.
-p
Process the input as a patch file, which often contains additional header information (often the default for piped input).
-R
Reverse the interpretation of additions and deletions. Lines previously marked as added will be counted as deleted, and vice-versa.
-v
Display version information of the diffstat utility and exit.
-w
Set the maximum width of the output line, specifically controlling the width of the histogram.
--files
Print only filenames and the total count of changed lines per file, omitting the detailed histogram.
--total
Print a grand total line at the end, summarizing all additions, deletions, and total changed lines across all files.
DESCRIPTION
diffstat reads the output of the diff command or a patch file and provides a concise summary of the changes. For each file, it typically displays the filename, the number of lines added, the number of lines deleted, and an ASCII-based graphical histogram representing these changes. This utility is invaluable for quickly understanding the scope and nature of modifications across multiple files in a patch or a large change set, offering a high-level overview without the need to review the full, detailed diff output. It helps in assessing the impact of code changes at a glance, making it easier to gauge the size and complexity of revisions.
CAVEATS
diffstat relies on receiving input in a standard diff format (e.g., unified, context, or normal diff). If the input is malformed or not recognized as a valid diff or patch, it may produce incorrect or no output. It only summarizes existing differences; it does not generate the diffs themselves. The graphical histogram is ASCII-based, so its visual appearance might vary slightly depending on the terminal emulator and font configuration.
COMMON USAGE PATTERN
The most common and effective way to use diffstat is by piping the output of a diff command (or any command producing diff-like output) directly into it. This allows for immediate summarization of changes.
Example 1: Summarizing a traditional file diff:
diff -u file1.c file2.c | diffstat
Example 2: Summarizing changes in a Git repository:
git diff | diffstat
VERSATILITY IN SCRIPTING
Due to its ability to process standard input and produce structured, human-readable output, diffstat is highly versatile for integration into shell scripts. It can be used as a component in automated workflows for code review, generating concise change reports, or as part of continuous integration/delivery pipelines where a quick, high-level overview of modifications is beneficial.
HISTORY
diffstat is a classic utility, typically distributed as part of the patchutils package, which provides a suite of tools for manipulating and applying patch files. Its development arose from the fundamental need to quickly digest and understand code changes encapsulated in traditional diff files – the predominant method of sharing code modifications before the widespread adoption of modern distributed Version Control Systems (VCS) like Git. While many contemporary VCS tools now offer built-in summary functionalities (e.g., git diff --stat), diffstat remains a robust and independent tool for analyzing plain diff output, particularly useful in shell scripting, legacy systems, or when dealing with generic patch formats.