grepdiff
Search patches for matching lines
SYNOPSIS
grepdiff [options] regexp [files…]
PARAMETERS
-0, --zero-files
Separate filenames with NUL instead of newline
-1, --first-match
Stop after first matching file
-C NUM, --context=NUM
Set context lines shown around hunks
-h, --hunk-only
Print only hunk headers/body, no filenames
-i, --ignore-case
Ignore case in regex matching
-I PATTERN, --include-from=PATTERN
Include only hunks from files matching PATTERN
-L LABEL, --label=LABEL
Use LABEL for filenames instead of actual
-n, --line-number
Prefix lines with numbers from original files
-N, --new-file
Treat absent files as empty
-q, --quiet
Suppress output; set exit status only
-r, --reverse
Match only on removed (-) lines
-s, --stats
Print match statistics instead of hunks
-t, --toggle
Invert match: added or removed lines
-v, --invert-match
Select hunks NOT matching regex
-x PATTERN, --exclude-from=PATTERN
Exclude hunks from files matching PATTERN
-z, --de-ANSI
Ignore ANSI color escapes in diffs
DESCRIPTION
grepdiff scans unified diff files (output from diff -u) and prints only the hunks (diff chunks) containing lines that match a given regular expression. Unlike plain grep, it understands diff format, reprinting entire matching hunks with headers, context, added (+), and removed (-) lines intact.
This is ideal for searching large patches or quilt series for changes to specific code, functions, or strings. For example, find all modifications to a variable without irrelevant noise. It supports file inclusion/exclusion, case-insensitivity, statistics, and more.
Input can be files or stdin; output mimics original patch structure for easy patch application or review. Part of patchutils package, enhancing patch workflows.
CAVEATS
Works best on unified diffs; may mishandle context/normal diffs. Regex is basic POSIX; no Perl extensions. Requires patchutils package.
EXAMPLES
grepdiff -i 'foo.*bar' changes.patch
Find hunks mentioning 'foo'/'bar' case-insensitive.
grepdiff -n --include=*.c 'malloc' ../patches/
Line-numbered C file changes with 'malloc'.
EXIT STATUS
0: matches found; 1: no matches; 2: errors.
HISTORY
Developed by Tim Waugh; first in patchutils 0.2.20 (2003). Evolved for quilt/patch workflows; stable, minimal changes since.
SEE ALSO
filterdiff(1), lsdiff(1), diffstat(1), patch(1), grep(1)


