patch
applies changes described in a patch file to original files
TLDR
Apply a patch
SYNOPSIS
patch [options] [original] [patchfile]
DESCRIPTION
patch applies changes described in a patch file to original files. Patch files are typically created by diff and contain instructions for adding, modifying, or removing lines.
The tool reads the patch file and attempts to apply each hunk (section of changes) to the target file. If a hunk doesn't match exactly, patch tries to find a location where it can apply with fuzz (allowing some context lines to differ).
patch is essential for software development, applying updates to source code, and managing code changes distributed as patches.
PARAMETERS
-p num
Strip num leading path components.-R, --reverse
Reverse the patch.-N, --forward
Ignore already applied patches.-b, --backup
Create backup files.-d dir, --directory= dir
Change to directory first.--dry-run
Don't modify files, show what would happen.-f, --force
Assume user knows best, don't ask.-i file, --input= file
Read patch from file.-o file, --output= file
Output to file.-F num, --fuzz= num
Set max fuzz factor.-l, --ignore-whitespace
Ignore whitespace changes.--verbose
Output debugging information.-E, --remove-empty-files
Remove empty files after patching.
CAVEATS
Patches may fail if files have changed since the diff was created. Fuzz can cause patches to apply in wrong locations. Always use --dry-run first for unfamiliar patches. Reverse patches should be applied in reverse order.
HISTORY
patch was written by Larry Wall in 1985 as part of his contributions to Unix tools. It became essential for distributing software changes before version control systems were widespread. The tool remains important for kernel development, where patches are the standard method for submitting changes.
