LinuxCommandLibrary

interdiff

Compare two patch files

TLDR

Compare diff files

$ interdiff [old_file] [new_file]
copy

Compare diff files, ignoring whitespace
$ interdiff [[-w|--ignore-all-space]] [old_file] [new_file]
copy

SYNOPSIS

interdiff [OPTION]... [PATCH1 [PATCH2]]

PARAMETERS

-d MIN, --min-arg-line=MIN
    Ignore hunks with line numbers below MIN

-D MAX, --max-arg-line=MAX
    Ignore hunks with line numbers above MAX

-L LABEL, --label=LABEL
    Use LABEL for file name and line number headers

-N, --show-function-line
    Include function name lines in context output

-o FILE, --output=FILE
    Write output to FILE instead of stdout

-p PREF, --strip-match=PREF
    Strip PREF path components from filenames

-q, --quiet
    Suppress hunk header output; report only differences

--help
    Display usage summary and exit

--version
    Print version information and exit

DESCRIPTION

The interdiff command, part of the GNU diffutils package, compares two diff or patch files and generates a new unified diff that captures the differences between them. This is invaluable in software development for analyzing incremental changes to patches, such as when refining a patch series or merging reviews.

It processes the input patches (PATCH1 and optionally PATCH2 from stdin) by aligning corresponding hunks based on file names, line numbers, and content. The output patch can be applied atop the first patch to produce the second, enabling efficient patch chaining or delta generation.

For example, developers use it in git workflows with git format-patch or quilt to compute minimal updates between patch versions. It handles unified and context diffs but performs best with unified format and matching hunk structures. Options allow filtering by line numbers, customizing labels, stripping path prefixes, and suppressing verbose output.

Key benefits include reducing patch size for review, automating patch evolution tracking, and aiding in distributed version control. Limitations arise with misaligned hunks or format mismatches, potentially requiring manual adjustment.

CAVEATS

Requires matching hunk structures and formats (unified preferred); fails on non-corresponding files or heavy reordering. Line numbers must align closely.

EXAMPLE USAGE

interdiff v1.patch v2.patch > delta.patch
Apply with: patch-2.7 -p1 < delta.patch

interdiff -p1 old.patch new.patch for path-stripped paths.

HISTORY

Introduced in GNU diffutils 2.7 (2001) by the Free Software Foundation to extend diff capabilities for patch comparison in collaborative development.

SEE ALSO

diff(1), patch(1), diff3(1), sdiff(1)

Copied to clipboard