LinuxCommandLibrary

diffstat

Summarize diff output statistics

TLDR

Display changes in a histogram

$ diff [path/to/file1] [path/to/file2] | diffstat
copy

Display inserted, deleted and modified changes as a table
$ diff [path/to/file1] [path/to/file2] | diffstat -t
copy

SYNOPSIS

diffstat [options] [file...]

PARAMETERS

-c
    Generate output suitable for use by patch -p1.

-d
    Debug mode.

-e file
    Use file to map filenames.

-k
    Show only filenames.

-l
    Count deleted lines, too.

-m
    Merge consecutive lines in the histogram.

-n width
    Set the width of the filename column to width.

-o file
    Write output to file.

-p lines
    Strip path components from filenames.

-r
    Report relative figures for insertions/deletions.

-s
    Suppress the histogram.

-t
    Suppress the filename column.

-v
    Show verbose output.

-w width
    Set the width of the histogram to width.

-x directory
    Like -p, but create a subdirectory.

DESCRIPTION

diffstat reads the output of a diff command and displays a histogram of the insertions, deletions, and modifications made to each file. It is commonly used to summarize the changes in a patch file or to provide an overview of the changes made in a code repository. diffstat parses the diff output to identify the files affected, the number of lines added, and the number of lines removed. The output is formatted in a tabular format, showing the filename, the number of added lines, the number of deleted lines, and optionally, a graphical representation of the changes. diffstat is a valuable tool for quickly assessing the size and scope of changes in a software project or any other text-based data. It can be used to identify potential problem areas, track code churn, and provide a high-level overview of the changes made by different developers or different versions of the software. Its simplicity and ease of use make it a popular choice for developers and system administrators alike. The command can read directly from the standard output, or files. This behavior is helpful to use it in shell pipes.

FILENAME MAPPING

The -e option allows you to map filenames. This is useful if the filenames in the diff output are different from the actual filenames on the system. The file specified with -e should contain a list of mappings, one per line, in the format 'oldfilename newfilename'.

HISTORY

diffstat has been a standard utility in Unix-like systems for a long time, its origins are closely tied to the development and use of the diff command. Over time, diffstat has remained relatively stable, with enhancements and bug fixes being incorporated to improve its accuracy and functionality. Its integration into various software development workflows and build systems has solidified its position as a valuable tool for code review and change tracking.

SEE ALSO

diff(1), patch(1)

Copied to clipboard