rediff
Reapply patch to a modified file
SYNOPSIS
rediff [OPTION]... OLDFILE NEWFILE [PATCHFILE]
PARAMETERS
-L LABEL
Uses LABEL instead of the actual file name in the output header for OLDFILE or NEWFILE.
--label=LABEL
Long form of -L.
-N
Treats any missing input files (OLDFILE or NEWFILE) as empty during the comparison.
--new-file
Long form of -N.
-S
Strips trailing carriage returns (CR) from all input lines before processing. Useful for cross-platform diffs.
--strip-trailing-cr
Long form of -S.
-V
Displays the rediff version information and exits.
--version
Long form of -V.
--help
Displays a help message with command usage and exits.
OLDFILE
The path to the original, base file that the diff was created from.
NEWFILE
The path to the target, modified file that the diff describes.
PATCHFILE
The path to the potentially hand-edited diff file. If omitted, rediff reads the diff content from standard input (stdin).
DESCRIPTION
rediff is a command-line utility from the GNU Diffutils package designed to make an edited diff output file usable again as input for the patch(1) command.
When a diff file, typically generated by diff -u or diff -c, is manually altered—for instance, by changing or removing context lines, or by introducing formatting errors—the patch command may fail to apply it correctly.
rediff addresses this issue by comparing the original source and target files (or their versions) with the potentially corrupted diff. It then attempts to recreate a valid unified or context diff that accurately represents the changes between the original files while incorporating the modifications specified in the edited diff. This process essentially re-generates the necessary context surrounding the changes, ensuring that the patch can be applied cleanly. It's particularly useful in scenarios where a patch needs minor adjustments but its apply-ability must be maintained.
CAVEATS
rediff is designed to fix common issues in hand-edited diffs, but it may not be able to perfectly reconstruct all diffs, especially if the original changes were ambiguous or the hand-editing significantly altered the diff's fundamental structure beyond minor context or formatting issues.
It primarily works with unified or context diff formats. For complex patch management or version control, dedicated systems like Git or SVN offer more robust solutions.
<B>USAGE EXAMPLE</B>
To fix a hand-edited unified diff file named edited.diff, which was originally generated between original_file_a.txt and original_file_b.txt, and save the corrected diff to fixed.diff:
rediff original_file_a.txt original_file_b.txt edited.diff > fixed.diff
This command will attempt to regenerate the diff, restoring correct context and formatting, making fixed.diff suitable for input to patch(1).
HISTORY
rediff is a component of the GNU Diffutils package, a suite of essential tools for comparing and merging files on Unix-like operating systems. The lineage of these tools, including diff and patch, traces back to the earliest versions of AT&T Unix.
While diff generates differences and patch applies them, rediff emerged to address a practical problem: the occasional need to manually adjust a diff script (e.g., to remove a specific change or correct a typo) without rendering it unusable by patch. Its development underscores the importance of maintaining patch integrity within software development and sharing workflows, particularly in environments where patches were frequently exchanged as email attachments or simple text files.