FILTERDIFF(1)
π FILTERDIFF β the manual, but make it cute
okay bestie, welcome to filterdiff(1) β she's a patch filter and she's that girl. Sit down, grab a strawberry, we're doing this π
β¨ NAME β¨
filterdiff β extract or exclude diffs from a diff file. like a little sieve for patches, no cap π«Ά
πΈ SYNOPSIS πΈ
filterdiff [[-i PATTERN] | [--include=PATTERN]] [[-I FILE] |
[--include-from-file=FILE]] [[-p n] | [--strip-match=n]]
[--strip=n] [--git-prefixes=strip|keep]
[--git-extended-diffs=exclude|include] [--addprefix=PREFIX]
[--addoldprefix=PREFIX] [--addnewprefix=PREFIX] [[-x PATTERN]
| [--exclude=PATTERN]] [[-X FILE] |
[--exclude-from-file=FILE]] [[-v] | [--verbose]] [--clean]
[--in-place] [[-z] | [--decompress]] [[-# RANGE] |
[--hunks=RANGE]] [--lines=RANGE] [[-FRANGE] |
[--files=RANGE]] [--annotate] [--format=FORMAT]
[--as-numbered-lines=WHEN] [--remove-timestamps] [file...]
filterdiff {[--help] | [--version] | [--list] | [--grep ...]}
like yes, that's a lot of brackets. she's complicated. she's worth it. π
π¦ DESCRIPTION π¦
So here's the vibe: you got a big pile of patches, and you only want the ones that touch specific files. That's literally it. filterdiff gives you a patch that applies to files matching the shell wildcard PATTERN β pulled out of a bigger collection of patches. Obsessed.
Say you wanna see the patches inside patch-2.4.3.gz that apply to every file called lp.c. You'd do:
filterdiff -z -i '*/lp.c' patch-2.4.3.gz
Periodt. β¨
Now β if you give neither -i nor -x, then -i '*' is just assumed. Which means filterdiff is also your go-to for spring cleaning an existing diff file: it can strip out the redundant lines from the beginning (the random text from the mail body, we've all been there π) or the junk sitting between the chunks (looking at you, CVS diffs). Wanna extract pure patch data? Run something like:
filterdiff message-with-diff-in-the-body > patch
She supports unified, context, and Git format diffs. And the Git format one? It comes with support for binary files, file renames, permission mode changes, and all the other Git-specific diff features. main character energy fr fr π
β οΈ Important little note: the way she interprets shell wildcard patterns does not treat slash characters or periods as special β in other words, no flags get passed tofnmatch. This is on purpose, so you can throw aroundβ*/basenameβ-type patterns without capping the number of pathname components. iykyk.
And yes β you can use both unified and context format diffs with this program. π
π OPTIONS π
-iPATTERN,--include=PATTERNβ only include files matching PATTERN. Everything else in the input gets suppressed. bye π-IFILE,--include-from-file=FILEβ only include files matching any pattern listed in FILE, one pattern per line. Everything else in the input gets suppressed.-xPATTERN,--exclude=PATTERNβ exclude files matching PATTERN. Everything else in the input gets displayed.-XFILE,--exclude-from-file=FILEβ exclude files matching any pattern listed in FILE, one pattern per line. Everything else in the input gets displayed.-pn,--strip-match=nβ when matching, ignore the first n components of the pathname.-#RANGE,--hunks=RANGEβ only include hunks within the specified RANGE. Hunks are numbered from 1, and the range is a comma-separated list of numbers orβfirst-lastβspans, optionally preceded by a modifierxwhich inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction.--lines=RANGEβ only include hunks that contain lines from the original file lying within the specified RANGE. Lines are numbered from 1, and the range is a comma-separated list of numbers orβfirst-lastβspans, optionally preceded by a modifierxwhich inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction.-F=RANGE,--files=RANGEβ only include files indicated by the specified RANGE. Files are numbered from 1 in the order they appear in the patch input, and the range is a comma-separated list of numbers orβfirst-lastβspans, optionally preceded by a modifierxwhich inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction.--annotateβ annotate each hunk with the filename and hunk number. little name tag, so cute π--format=unified|contextβ use the specified output format.--strip=nβ remove the first n components of pathnames in the output.--git-prefixes=strip|keepβ how to handle thea/andb/prefixes in Git diff filenames. Withstrip, it removes the prefixes both for filename matching (when you're using-iand-x) and for filename output (similar to--strip). Withkeep(the default), it preserves existing behavior. This applies to both Git-specific diffs (binary files, renames, mode changes) and traditional diffs when they're part of a Git patch. Heads up though: withkeep, copy and rename operations are treated as if they hada/andb/prefixes, for consistency with other Git operations. And mark the date bestie β the default will change tostripin version 0.5.0. π--git-extended-diffs=exclude|includeβ controls whether to process Git diffs without traditional content hunks. That means renames, copies, mode-only changes, and binary files. Withexclude(default in 0.4.x), these diffs get skipped. Withinclude(default in 0.5.0+), these diffs get processed normally. This option affects file numbering with-Nand file filtering with-F.--addprefix=PREFIXβ prefix pathnames in the output by PREFIX. This overrides any individual settings you specified with--addoldprefixor--addnewprefix. she's the boss π--addoldprefix=PREFIXβ prefix pathnames for old or original files in the output by PREFIX.--addnewprefix=PREFIXβ prefix pathnames for updated or new files in the output by PREFIX.--as-numbered-lines=before|after|original-before|original-afterβ instead of showing a patch fragment, display the lines of the selected hunks with the line number of the file before (or after) the patch is applied, followed by a TAB character and a colon, at the beginning of each line. Every hunk except the first will have a line consisting ofβ...βbefore it.
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. so thoughtful of her π₯Ή
--remove-timestampsβ do not include file timestamps in the output.-v,--verboseβ always show non-diff lines in the output. By default, non-diff lines are only shown when excluding a filename pattern.--cleanβ always remove all non-diff lines from the output. Even when excluding a filename pattern. scrubbed. immaculate. β¨--in-placeβ write output to the original input files instead of standard output. This lets you filter multiple patch files without manual redirection loops. no shell gymnastics required π«Ά-z,--decompressβ decompress files with extensions.gzand.bz2.--helpβ display a short usage message.--versionβ display the version number offilterdiff.--listβ behave likelsdiff(1)instead. she's method acting π--grepβ behave likegrepdiff(1)instead.
β EXAMPLES β
Wanna see all the patch hunks that affect the first five lines of a C file? say less:
filterdiff -i '*.c' --lines=-5 < patch
Wanna see the first hunk of each file patch?
filterdiff -#1 patchfile
Wanna see patches modifying a ChangeLog file in a subdirectory?
filterdiff -p1 Changelog
Wanna see the complete patches for each patch that modifies line 1 of the original file? okay:
filterdiff --lines=1 patchfile | lsdiff | \
xargs -rn1 filterdiff patchfile -i
Wanna see all but the first hunk of a particular patch? you might use:
filterdiff -p1 -i file.c -#2- foo-patch
And if you have a very specific list of hunks in a patch that you want to see, just list them out:
filterdiff -#1,2,5-8,10,12,27-
Wanna see the lines of the files that would be patched as they'll appear after the patch is applied?
filterdiff --as-numbered-lines=after patch.file
You can see the same context before the patch is applied with:
filterdiff --as-numbered-lines=before
patch.file
And for CI/CD systems that need line numbers matching the original diff context (useful for error reporting), use the original-* variants:
filterdiff --as-numbered-lines=original-after patch.file
Oh and β filterdiff can also be used to convert between unified and context format diffs:
filterdiff -v --format=unified context.diff
And one more time for the people in the back: Git format diffs are fully supported, including binary files, file renames, and permission mode changes. π
π SEE ALSO π
π§ AUTHOR π§
Tim Waugh <twaugh@redhat.com> β Package maintainer
okay that's the whole thing, you're officially a filterdiff girly now π«Ά sending you the biggest slay, bestie.
this page came to you from the patchutils girls, dated 23 Jan 2009 β and yes she's still iconic, no notes, periodt π β¨
π¦ where this page comes from
- alpine 3.24: patchutils-doc 0.4.5-r0 Β· GPL-2.0-or-later
- arch rolling: patchutils 0.4.5-1 Β· GPL-2.0-only
- ubuntu stonking: patchutils 0.4.5-1ubuntu1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms