| GREPDIFF(1) | Man pages | GREPDIFF(1) |
NAME
grepdiff - show files modified by a diff containing a regex
SYNOPSIS
grepdiff [[-n] | [--line-number]] [[-N] | [--number-files]] [[-p n] | [--strip-match=n]] [--strip=n] [--git-prefixes=strip|keep] [--git-extended-diffs=exclude|include] [--addprefix=PREFIX] [--addoldprefix=PREFIX] [--addnewprefix=PREFIX] [[-s] | [--status]] [--empty-files-as-absent] [[-i PATTERN] | [--include=PATTERN]] [[-I FILE] | [--include-from-file=FILE]] [[-x PATTERN] | [--exclude=PATTERN]] [[-X FILE] | [--exclude-from-file=FILE]] [[-# RANGE] | [--hunks=RANGE]] [--lines=RANGE] [[-FRANGE] | [--files=RANGE]] [--annotate] [--as-numbered-lines=WHEN] [--format=FORMAT] [--remove-timestamps] [[-v] | [--verbose]] [[-z] | [--decompress]] [[-E] | [--extended-regexp]] [[-H] | [--with-filename]] [[-h] | [--no-filename]] [--output-matching=WHAT] [--only-match=WHAT] {[REGEX] | [-f FILE]} [file...]
grepdiff {[--help] | [--version] | [--list] | [--filter ...]}
DESCRIPTION
For each file modified by a patch, if the patch hunk contains the REGEX then the file's name is printed.
The regular expression is treated as POSIX Basic Regular Expression syntax, unless the -E option is given in which case POSIX Extended Regular Expression syntax is used. When compiled with PCRE2 support, PCRE regular expressions are used instead of POSIX regular expressions, and the -E option has no effect since PCRE already supports extended regular expression features by default.
You can use unified, context, and Git format diffs with this program. Git format includes support for binary files, file renames, permission mode changes, and other Git-specific diff features.
OPTIONS
-n, --line-number
For a description of the output format see lsdiff(1).
-N, --number-files
-pn, --strip-match=n
--strip=n
--git-prefixes=strip|keep
--git-extended-diffs=exclude|include
--addprefix=PREFIX
--addoldprefix=PREFIX
--addnewprefix=PREFIX
-s
--empty-files-as-absent
-iPATTERN, --include=PATTERN
-IFILE, --include-from-file=FILE
-x PATTERN --exclude=PATTERN
-XFILE, --exclude-from-file=FILE
-#RANGE, --hunks=RANGE
--lines=RANGE
-F=RANGE, --files=RANGE
--annotate
--as-numbered-lines=before|after|original-before|original-after
The before and after options show line numbers adjusted for any skipped hunks. The original-before and original-after options show line numbers as they appear in the original diff, preserving the original line number context. This is useful for CI/CD systems that need to report errors on the exact line numbers from the original diff.
--format=unified|context
--remove-timestamps
-z, --decompress
-E, --extended-regexp
-H, --with-filename
-h, --no-filename
-fFILE, --file=FILE
--output-matching=hunk|file
--only-match=rem|removals|add|additions|mod|modifications|all
--help
--version
--filter
--list
EXAMPLES
To quickly identify which files in a large patch contain memory allocation changes (useful for code review):
grepdiff "malloc\|free\|realloc" large-patch.diff
This shows only the filenames, giving you a quick overview without being overwhelmed by diff content.
To see the actual hunks containing the pattern:
grepdiff --output-matching=hunk "malloc" patch.diff
To see complete file diffs for files containing the pattern:
grepdiff --output-matching=file "malloc" patch.diff
For CI/CD systems that need line numbers matching the original diff context (useful for error reporting):
grepdiff pattern --output-matching=hunk \ --as-numbered-lines=original-after patch.file
Git format diffs are fully supported. For example, to find files in a git patch that contain changes to malloc calls:
grepdiff "malloc" git-patch.patch
Note that grepdiff searches in the hunk content (the actual code changes), not in Git metadata like rename headers. Files with only renames or mode changes (no content hunks) won't be found even if the pattern appears in the Git headers.
SEE ALSO
AUTHOR
Tim Waugh <twaugh@redhat.com>
| 10 Feb 2011 | patchutils |