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 to fnmatch. 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 modifier x which 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 modifier x which 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 modifier x which 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 the a/ and b/ prefixes in Git diff filenames. With strip, it removes the prefixes both for filename matching (when you're using -i and -x) and for filename output (similar to --strip). With keep (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: with keep, copy and rename operations are treated as if they had a/ and b/ prefixes, for consistency with other Git operations. And mark the date bestie β€” the default will change to strip in 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. With exclude (default in 0.4.x), these diffs get skipped. With include (default in 0.5.0+), these diffs get processed normally. This option affects file numbering with -N and file filtering with -F.
  • --addprefix=PREFIX β€” prefix pathnames in the output by PREFIX. This overrides any individual settings you specified with --addoldprefix or --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 .gz and .bz2.
  • --help β€” display a short usage message.
  • --version β€” display the version number of filterdiff.
  • --list β€” behave like lsdiff(1) instead. she's method acting πŸ‘‘
  • --grep β€” behave like grepdiff(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