Patch (Unix)

Patch (Unix)

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.

History

The original patch program was written by Larry Wall (who went on to create the Perl programming language) and [http://groups-beta.google.com/group/mod.sources/browse_thread/thread/c5240ceb77b7f586/488b0929254d936a posted to mod.sources] (which later became comp.sources.unix) in May 1985. A newer version of the program is part of the GNU project and is maintained by the FSF.

Usage context

Developed by a programmer for other programmers, patch was frequently used for updating of source code to a newer version. Because of this many people came to associate patches with source code, whereas patches can in fact be applied to any text. It should be noted that "patched" files do not accumulate any unneeded cruft, which is what some people perceive based on the English meaning of the word; patch is as capable of removing text as it is of adding it. Patches described here should not be confused with binary patches distributed by closed-source software manufacturers to update binary files containing the program to a new release.

Patches in software development

The diff files that serve as input to patch are readable text files, which means that they can be easily reviewed or modified by humans before use.

In addition to the "diff" program, diffs can also be produced by other programs, such as Subversion, CVS, and RCS.

Patches have been the crucial component of many source control systems, including CVS.

Advanced diffs

When more advanced diffs are used, patches can be applied even to files that have been modified in the meantime, as long as those modifications do not interfere with the patch. This is achieved by using "context diffs" and "unified diffs" (also known as "unidiffs"), which surround each change with "context", which is the text immediately before and after the changed part. Patch can then use this context to locate the region to be patched even if it has been displaced by changes earlier in the file, using the line numbers in the diffs as a starting point. Because of this property, context and unified diffs are the preferred form of patches for submission to many software projects.

The above features make diff and patch especially popular for exchanging modifications to free software. Outsiders can download the latest publicly available source code, make modifications to it, and send them, in diff form, to the development team. Using diffs, the development team has the ability to effectively review the patches before applying them, and can apply them to a newer code base than the one the outside developer had access to.

Usage examples

To create a patch, one could run the following command in a shell:

$ diff -u oldFile newFile > mods.diff # -u tells diff to output unified diff format

To apply a patch, one could run the following command in a shell:

$ patch < mods.diff

This tells patch to apply the changes to the specified files described in mods.diff. Patches to files in subdirectories require the additional -p"number" option, where "number" is 1 if the base directory of the source tree is included in the diff, and 0 otherwise.

Patches can be undone, or reversed, with the '-R' option:

$ patch -R < mods.diff

If the file is not identical to the version the diff was generated against, the patch will not be able to be applied cleanly. For example, if lines of text are inserted at the beginning, the line numbers referred to in the patch will be incorrect. patch is able to recover from this, by looking at nearby lines to relocate the text to be patched. It will also recover when lines of context (for context and unified diffs) are altered; this is described as fuzz.

Ports of patch

Originally written for Unix and Unix-like systems, patch has also been ported to Windows and many other platforms. Windows ports of patch are provided by GnuWin32 and UnxUtils.

See also

* diff
* Patch (computing)
* rsync
* List of Unix programs
* IBM Mainframe utility IEBUPDTE a mainframe patch program, created about 20 years earlier (circa ~1964).

External links

*
* [http://freshmeat.net/projects/patchutils/ patchutils] - Additional utility programs for manipulating patches.
* [http://gnuwin32.sourceforge.net/ GNU tools for Win32] - Win32 port of tools, including diff and patch.
* [http://invisible-island.net/diffstat/ diffstat] - show statistics from output of diff.


Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Look at other dictionaries:

  • Patch (UNIX) — patch  программная утилита Unix, предназначенная для переноса правок (изменений) между разными версиями текстовых файлов. Информация о правке обычно содержится в отдельном файле, называемом «правкой» или «файлом правки» (англ. patch file).… …   Википедия

  • patch (UNIX) — patch Разработчик Andreas Gruenbacher, Jim Meyering Операционная система Кроссплатформенное программное обеспечение Последняя версия 2.7 (12 сентября 2012) Лицензия GPL Сайт …   Википедия

  • Patch (Unix) — Patch (informatique) Pour les articles homonymes, voir Patch. Un patch (terme anglais) est une section de code que l on ajoute à un logiciel, pour y apporter des modifications : correction d un bogue, traduction, crack. Le terme officiel en… …   Wikipédia en Français

  • Patch (Unix) — Das Unix Programm patch manipuliert Quelltext anhand eines Patches. Es ist somit das Gegenstück zu dem Programm diff, das Patches erzeugt. Inhaltsverzeichnis 1 Hintergrund 2 Anwendung 3 Interoperabilität mit …   Deutsch Wikipedia

  • Patch (computing) — Software update redirects here. For the software tool by Apple Inc., see Apple Software Update. For the Unix program, see patch (Unix). For the file format, see diff. A patch is a piece of software designed to fix problems[1] with, or update a… …   Wikipedia

  • Patch — The term patch may refer to:Textiles* Embroidered patch, an embroidered design applied to clothing by organizations or individuals * Eyepatch, used in the treatment of eye disorders, or for aesthetic purposes in covering an injured or missing eye …   Wikipedia

  • Patch (Software) — Ein Patch (von engl. Flicken, in der Bedeutung von Nachbesserung, auch Bugfix) ist eine Korrekturauslieferung für Software oder Daten aus Endanwendersicht, um zum Beispiel Sicherheitslücken zu schließen, Fehler zu beheben oder bislang nicht… …   Deutsch Wikipedia

  • Patch — Das Wort Patch [pæʧ] (engl. für „Flicken“) bezeichnet Patch Clamp Technik, eine elektrophysiologische Technik zur Untersuchung von Ionenkanälen ein medizinisches Implantat; siehe Patch (Medizin) den Patch Test, einen Allergietest, siehe… …   Deutsch Wikipedia

  • UNIX — Ken Thompson und Dennis Ritchie Basisdaten Entwickler …   Deutsch Wikipedia

  • Unix — Kommandozeile (Unix Prompt) Basisdaten Entwickler Ken Thompso …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”