Skip to content
Search

Patch

lastmod 2018-08-17created 2014-09-294 edits

The computer tool patch is a Unix program that updates text files according to instructions contained in a separate file, called a patch file. The patch file (also called a patch for short) is a text file that consists of a list of differences and is produced by running the related diff program with the original and updated file as arguments. Updating files with patch is often referred to as applying the patch or simply patching the files.

Options

-p[숫자]
Applies the patch after stripping parent paths. If you enter -p0, no parent path is stripped; if you enter -p1, one parent path is stripped before applying.

Example

Applies the patch after stripping one top-level parent path.

$ patch -p1 < [Patch파일명]

Troubleshooting

A collection of problems related to patch.

Hunk FAILED

If an error message like the one below is printed, it is likely caused by a whitespace-related problem.

$ patch -p0 < foo.diff
patching file user.php
Hunk #1 FAILED at 1140.
1 out of 1 hunk FAILED -- saving rejects to file user.php.rej

In this case, add the -l option as shown below.

$ patch -l -p0 < foo.diff

See also

Favorite site