flipdiff
Convert between unified and context diff formats
SYNOPSIS
flipdiff [options] [file]
PARAMETERS
-p NUM
Strip NUM leading components from filenames in paths.
-U NUM
Set number of context lines to NUM (default from input).
-L LABEL
Use LABEL instead of filename in output header.
-o FILE, --output=FILE
Write output to FILE instead of stdout.
--help
Display usage summary and exit.
--version
Output version information and exit.
DESCRIPTION
flipdiff is a command-line utility from the patchutils package designed to reverse the direction of differences in unified diff files. It transforms lines marked for deletion (-) into additions (+) and vice versa, while preserving unchanged context lines. This is particularly useful when a patch needs to be applied in reverse—for example, to undo changes or correct a patch generated from the wrong file order.
By flipping the hunk signs, flipdiff enables tools like patch to apply the inverted diff correctly. It handles standard unified diff format (diff -u) reliably and supports multiple files or stdin input. Common workflows include generating a reversed patch for distribution or testing revert scenarios.
Limitations apply to non-unified formats or complex diffs with binary files, where results may be unpredictable. Always verify the output with diff before applying.
CAVEATS
Works only on unified diffs; context, normal, or ed formats are unsupported or produce errors. Complex diffs (e.g., with function headers or binaries) may flip incorrectly—validate output before use.
EXAMPLE
flipdiff input.patch > reversed.patch
Applies reversed patch: patch -p1 < reversed.patch
HISTORY
Developed by Tim Waugh as part of GNU patchutils (first released ~2002). Evolved to handle modern diff features; maintained in most Linux distros via patchutils package.
SEE ALSO
filterdiff(1), lsdiff(1), patch(1), diff(1)


