LinuxCommandLibrary

patch

Apply differences between files (patching)

TLDR

Apply a patch using a diff file (filenames must be included in the diff file)

$ patch < [patch.diff]
copy

Apply a patch to a specific file
$ patch < [patch.diff] [path/to/file]
copy

Patch a file writing the result to a different file
$ patch < [patch.diff] [path/to/input_file] [[-o|--output]] [path/to/output_file]
copy

Apply a patch to the current directory
$ patch < [patch.diff] [[-p|--strip]] 1
copy

Apply the reverse of a patch
$ patch < [patch.diff] [[-R|--reverse]]
copy

SYNOPSIS

patch [options] [original [patchfile]]

PARAMETERS

-p NUM
    Strip NUM leading components from paths

-b, --backup
    Create backup files

-d DIR
    Change to directory before patching

-i FILE
    Read patch from file

-R, --reverse
    Assume patch was created reversed

-N, --forward
    Ignore already-applied patches

-E, --remove-empty-files
    Remove files that become empty

--dry-run
    Don't actually change files

-v, --verbose
    Verbose output

-s, --silent
    Silent except for errors

DESCRIPTION

patch applies changes from diff files to original files. It reads a patch file containing differences between two versions and applies those changes to create the newer version. patch is essential for applying software updates, bug fixes, and modifications distributed as diff files.

CAVEATS

Patches may fail if source has changed. Use --dry-run to test first. The -p option usually needs adjustment. Fuzzy matching can cause incorrect placement.

SEE ALSO

diff(1), quilt(1), git-apply(1), interdiff(1)

Copied to clipboard