patch (Unix)

from Wikipedia, the free encyclopedia

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 diffprogram 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. patchbecame 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 patchthe 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, patchthe parameter must -p0be passed.

The parameter -Rcan 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