patch (Unix)
The command line program patch is mainly used in programming to make improvements to the source code of a software project available to other developers . Only the changes in the source code due to a software patch compared to an older version of the corresponding file are used. For example, a programmer can transmit the output of the diff
program to another, who then uses the data as input for patch
.
background
The first implementation was written by Larry Wall and ran on Unix-like operating systems. It has since been ported to numerous platforms and is part of the POSIX standard and most IDEs . The program can apply many different formats of patches and has become a popular way for developers to share changes to a program with one another. patch
became particularly popular within the free software community because it allows developers to contribute to a project quickly and easily without having write access to version control the project.
application
To apply a patch, this command is sufficient:
$ patch -p1 < bearbeitungen.diff
This command causes patch
the changes to the files specified in the patch editions.diff to be applied and the first directory component of the path to the files to be skipped. Patches are often created so that the main directory of the source code tree is contained in the patch, but if the files are to be patched from within the main directory, patch
the parameter must -p0
be passed.
The parameter -R
can be used to undo changes to a patch that has been applied once.
Windows interoperability
When using patches created on a Windows machine, it is sometimes necessary to address the CR / LF problem in order for the patch to be applicable. This is done, for example, through
$ sed -e '/^Index:/ {N;N;N;s/\r//g}' bearbeitungen_unter_Windows.diff > bearbeitungen.unix.diff $ patch -p1 < bearbeitungen.unix.diff
Web links
- GNU patch project page
-
patch
: patch - apply changes to files - Open Group Base Specification -
patch(1)
: apply a diff file to an original - Debian GNU / Linux Executables or Shell Commands man page -
patch(1)
: apply a diff file to an original - OpenBSD General Commands Manual