Patch (Unix) - Wikipedia - Recent changes [en]

1 week ago 385

Examples: focus on patch; not diff

← Previous revision Revision as of 17:22, 16 July 2025
Line 52: Line 52:


==Examples==
==Examples==
The following command creates a patch file, {{code|mods.diff}}, that encodes how to generate {{code|newFile}} from {{code|oldFile}}. The {{code|-u}} option selects to output in unified diff format.
The following command creates a patch file, {{code|patchFile}}, that encodes how to generate {{code|newFile}} from {{code|oldFile}}. The {{code|-u}} option selects to output in unified diff format.


<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
$ diff -u oldFile newFile > mods.diff
$ diff -u oldFile newFile > patchFile
</syntaxhighlight>
</syntaxhighlight>


The following command applies the changes to the file identified in <code>mods.diff</code>.
The following command applies the changes to the file identified in <code>patchFile</code>.


<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
$ patch < mods.diff
$ patch < patchFile
</syntaxhighlight>
</syntaxhighlight>


Line 69: Line 69:


<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
$ patch -R < mods.diff
$ patch -R < patchFile
</syntaxhighlight>
</syntaxhighlight>


Open Full Post