Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Patch (Unix)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Unix utility to apply changes to text files}} {{lowercase|title=patch (Unix)}} {{Infobox software | name = patch | logo = | screenshot = TuxOnIce patching.png | screenshot size = | caption = A screenshot of using patch | author = [[Larry Wall]] | developer = Paul Eggert, Wayne Davison, David MacKenzie, Andreas Grünbacher | released = {{Start date and age|1985|05|24}} | latest release version = | latest release date = | operating system = [[Unix]] and [[Unix-like]], [[Plan 9 from Bell Labs|Plan 9]], [[MSX-DOS]], [[Microsoft Windows]] | platform = [[Cross-platform]] | genre = [[Command (computing)|Command]] | license = | website = }} The computer tool '''patch''' is a [[Unix]] [[computer program|program]] that updates [[text file]]s 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 posted to <code>mod.sources</code><ref>{{cite newsgroup |url=https://groups.google.com/g/mod.sources/c/xSQM63e39YY/m/apNNJSkJi0gJ |newsgroup=mod.sources |title=patch version 1.3 |first=Larry |last=Wall |author-link=Larry_Wall |date=May 8, 1985 |access-date=2024-07-14 |url-status=live |archive-url=https://web.archive.org/web/20230404223018/https://groups.google.com/g/mod.sources/c/xSQM63e39YY/m/apNNJSkJi0gJ |archive-date=2023-04-04 }}</ref> (which later became <code>comp.sources.unix</code>) in May 1985. patch was added to XPG4, which later became [[POSIX]].<ref>{{man|cu|patch|SUS}}</ref> Wall's code remains the basis of "patch" programs provided in [[OpenBSD]],<ref>http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/patch/ {{Webarchive|url=https://web.archive.org/web/20170607120135/http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/patch/ |date=2017-06-07 }} OpenBSD patch source</ref> [[FreeBSD]],<ref>{{man|1|FreeBSD}}</ref> and schilytools.<ref>{{cite web | url=https://codeberg.org/schilytools/schilytools/src/branch/master/patch/patch.c | title=Schilytools }}</ref>{{dubious|wall-vs-gnu|date=August 2024}} The [[Open Software Foundation]], which merged into [[The Open Group]], is said to have maintained a derived version.{{dubious|wall-vs-gnu|date=August 2024}} The [[GNU project]]/[[Free Software Foundation|FSF]] maintains its patch, forked from the Larry Wall version. The repository is different from that of GNU diffutils, but the documentation is managed together.<ref>{{cite web | url=https://git.savannah.gnu.org/cgit/patch.git/tree/src/patch.c | title=Patch.c\SRC - patch.git - GNU patch }}</ref> ==Usage context== Developed by a programmer for other programmers, patch was frequently used for updating [[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. ''Patched'' files do not accumulate any unneeded text, 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 [[Patch (computing)|binary patches]], which, although can be conceptually similar, are distributed to update binary files comprising 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 (software)|Subversion]], [[Concurrent Versions System|CVS]], [[Revision Control System|RCS]], [[Mercurial (software)|Mercurial]] and [[Git (software)|Git]]. Patches have been the crucial component of many [[source control]] systems, including [[Concurrent Versions System|CVS]]. ===Advanced diffs=== {{further|diff#Variations}} 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 "[[diff#Context format|context diffs]]" and "[[diff#Unified format|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 [[open-source 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: <syntaxhighlight lang="console"> $ diff -u oldFile newFile > mods.diff # -u tells diff to output unified diff format </syntaxhighlight> To apply a patch, one could run the following command in a shell: <syntaxhighlight lang="console"> $ patch < mods.diff </syntaxhighlight> This tells patch to apply the changes to the specified files described in <code>mods.diff</code>. Patches to files in subdirectories require the additional <code>-p''number''</code> 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 '<code>-R</code>' option: <syntaxhighlight lang="console"> $ patch -R < mods.diff </syntaxhighlight> In some cases when 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 [[Microsoft Windows|Windows]] and many other platforms. Windows ports of patch are provided by [[GnuWin32]] and [[UnxUtils]]. A <code>patch</code> command is also part of [[ASCII Corporation|ASCII]]'s ''MSX-DOS2 Tools'' for [[MSX-DOS]] version 2.<ref>[https://archive.org/details/MSXDOS2TOOLS MSX-DOS2 Tools User's Manual by ASCII Corporation]</ref> ==See also== * [[Patch (computing)]] * [[Quilt (software)]] * [[rsync]] * [[xdelta]] * [[List of Unix commands]] * [[IBM mainframe utility programs#IEBUPDTE|IBM Mainframe utility IEBUPDTE]] a mainframe patch program, created about 20 years earlier (circa ~1964). ==References== {{Reflist}} ==External links== {{Wikibooks|Guide to Unix|Commands}} *[https://www.gnu.org/software/diffutils/ GNU Diffutils] (includes diff and patch); [https://www.gnu.org/software/diffutils/manual/html_node/Merging-with-patch.html#Merging-with-patch Documentation] *[http://gnuwin32.sourceforge.net/ GNU tools for Win32]{{spaced ndash}}Win32 port of tools, including diff and patch * {{cite web |url=https://invisible-island.net/diffstat/ |title=DIFFSTAT – make histogram from diff-output |last=Dickey |first=Thomas E. |access-date=2020-05-01 |url-status=live |archive-url=https://web.archive.org/web/20200122063404/https://invisible-island.net/diffstat/ |archive-date=2020-01-22 |postscript=none}} {{Unix commands}} [[Category:1984 software]] [[Category:Patch utilities]] [[Category:Plan 9 commands]] [[Category:Unix SUS2008 utilities]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite newsgroup
(
edit
)
Template:Cite web
(
edit
)
Template:Dubious
(
edit
)
Template:Fix
(
edit
)
Template:Further
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox software
(
edit
)
Template:Lowercase
(
edit
)
Template:Main other
(
edit
)
Template:Man
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Spaced ndash
(
edit
)
Template:Template other
(
edit
)
Template:Unix commands
(
edit
)
Template:Webarchive
(
edit
)
Template:Wikibooks
(
edit
)