LinuxCommandLibrary

filterdiff

Filter patches by filename and content

SYNOPSIS

filterdiff [options] [--] [files…]

PARAMETERS

-i, --include=PATTERN
    Add file name pattern to include list (shell glob or regex)

-I, --include-from-file=FILE
    Read include file patterns from FILE

-x, --exclude=PATTERN
    Add file name pattern to exclude list

-X, --exclude-from-file=FILE
    Read exclude file patterns from FILE

#, --number=NUM
    Include/exclude patches by number (e.g., #3)

-p N
    Strip N leading path components from filenames

--hunks=PATTERN
    Include hunks where context matches PATTERN

--lines=PATTERN
    Include hunks where @@ line range matches PATTERN

--annotate
    Prefix output hunks with source filename

--addprefix=PREFIX
    Prepend PREFIX to all filenames in patches

--format=unified|context|ed
    Set output patch format

--trivial-ok
    Allow patches with no line changes

--quiet
    Suppress mismatch warnings

--output=FILE
    Write output to FILE

--outdir=DIR
    Write each patch to DIR/NUM

--help
    Display usage summary

--version
    Print version information

DESCRIPTION

filterdiff is a utility from the patchutils package that selectively extracts patches from one or more unified diff files based on user-defined criteria. It processes input diffs (from sources like git format-patch or diff -u) and outputs only the matching patches, making it ideal for isolating changes to specific files, functions, or line ranges in large patch series.

Key use cases include:
• Extracting changes for particular source files amid project-wide diffs.
• Filtering hunks by context patterns or line numbers.
• Annotating output with source filenames for clarity.

The tool preserves patch numbering, format (unified, context, etc.), and metadata, enabling seamless integration with tools like patch, quilt, or git am. It supports reading patterns from files for complex filters and can write output to files or directories. Warnings are issued for ambiguous matches, but --quiet suppresses them. Overall, filterdiff streamlines patch management in development workflows.

CAVEATS

Patterns are matched against full paths; use --strip or -p for basename matching. Excludes take precedence over includes. Non-unified diffs may not parse correctly. Large inputs can be memory-intensive.

EXAMPLE

filterdiff -i '*.c' *.patch
Extracts all C file patches from input files.

PATTERN SYNTAX

Shell globs by default; prefix with /regex/ for regex (e.g., /func.*[({]/ for function hunks).

HISTORY

Developed by Tim Waugh as part of patchutils (first release ~2002). Enhanced in GNU patchutils 0.6+ (2016) with better regex support and output options. Maintained sporadically; current in most distros via patchutils package.

SEE ALSO

lsdiff(1), interdiff(1), patch(1), diff(1)

Copied to clipboard