/usr/share/doc/diffutils-doc/Making-Patches.html is in diffutils-doc 1:3.5-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This manual is for GNU Diffutils
(version 3.5, 4 August 2016),
and documents the GNU diff, diff3,
sdiff, and cmp commands for showing the
differences between files and the GNU patch command for
using their output to update files.
Copyright (C) 1992-1994, 1998, 2001-2002, 2004, 2006, 2009-2016 Free
Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled
"GNU Free Documentation License." -->
<!-- Created by GNU Texinfo 6.3, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Comparing and Merging Files: Making Patches</title>
<meta name="description" content="Comparing and Merging Files: Making Patches">
<meta name="keywords" content="Comparing and Merging Files: Making Patches">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Index.html#Index" rel="index" title="Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="index.html#Top" rel="up" title="Top">
<link href="Invoking-cmp.html#Invoking-cmp" rel="next" title="Invoking cmp">
<link href="Merging-with-patch.html#patch-and-Tradition" rel="prev" title="patch and Tradition">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en">
<a name="Making-Patches"></a>
<div class="header">
<p>
Next: <a href="Invoking-cmp.html#Invoking-cmp" accesskey="n" rel="next">Invoking cmp</a>, Previous: <a href="Merging-with-patch.html#Merging-with-patch" accesskey="p" rel="prev">Merging with patch</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Tips-for-Making-and-Using-Patches"></a>
<h2 class="chapter">11 Tips for Making and Using Patches</h2>
<p>Use some common sense when making and using patches. For example,
when sending bug fixes to a program’s maintainer, send several small
patches, one per independent subject, instead of one large,
harder-to-digest patch that covers all the subjects.
</p>
<p>Here are some other things you should keep in mind if you are going to
distribute patches for updating a software package.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Tips-for-Patch-Producers" accesskey="1">Tips for Patch Producers</a>:</td><td> </td><td align="left" valign="top">Advice for making patches.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Tips-for-Patch-Consumers" accesskey="2">Tips for Patch Consumers</a>:</td><td> </td><td align="left" valign="top">Advice for using patches.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Avoiding-Common-Mistakes" accesskey="3">Avoiding Common Mistakes</a>:</td><td> </td><td align="left" valign="top">Avoiding common mistakes when using <code>patch</code>.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Generating-Smaller-Patches" accesskey="4">Generating Smaller Patches</a>:</td><td> </td><td align="left" valign="top">How to generate smaller patches.
</td></tr>
</table>
<hr>
<a name="Tips-for-Patch-Producers"></a>
<div class="header">
<p>
Next: <a href="#Tips-for-Patch-Consumers" accesskey="n" rel="next">Tips for Patch Consumers</a>, Up: <a href="#Making-Patches" accesskey="u" rel="up">Making Patches</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Tips-for-Patch-Producers-1"></a>
<h3 class="section">11.1 Tips for Patch Producers</h3>
<a name="index-patch-producer-tips"></a>
<p>To create a patch that changes an older version of a package into a
newer version, first make a copy of the older and newer versions in
adjacent subdirectories. It is common to do that by unpacking
<code>tar</code> archives of the two versions.
</p>
<p>To generate the patch, use the command ‘<samp>diff -Naur <var>old</var>
<var>new</var></samp>’ where <var>old</var> and <var>new</var> identify the old and new
directories. The names <var>old</var> and <var>new</var> should not contain any
slashes. The <samp>-N</samp> option lets the patch create and remove
files; <samp>-a</samp> lets the patch update non-text files; <samp>-u</samp>
generates useful time stamps and enough context; and <samp>-r</samp> lets
the patch update subdirectories. Here is an example command, using
Bourne shell syntax:
</p>
<div class="example">
<pre class="example">diff -Naur gcc-3.0.3 gcc-3.0.4
</pre></div>
<p>Tell your recipients how to apply the patches. This should include
which working directory to use, and which <code>patch</code> options to
use; the option ‘<samp>-p1</samp>’ is recommended. Test your procedure by
pretending to be a recipient and applying your patches to a copy of
the original files.
</p>
<p>See <a href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a>, for how to avoid common mistakes when
generating a patch.
</p>
<hr>
<a name="Tips-for-Patch-Consumers"></a>
<div class="header">
<p>
Next: <a href="#Avoiding-Common-Mistakes" accesskey="n" rel="next">Avoiding Common Mistakes</a>, Previous: <a href="#Tips-for-Patch-Producers" accesskey="p" rel="prev">Tips for Patch Producers</a>, Up: <a href="#Making-Patches" accesskey="u" rel="up">Making Patches</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Tips-for-Patch-Consumers-1"></a>
<h3 class="section">11.2 Tips for Patch Consumers</h3>
<a name="index-patch-consumer-tips"></a>
<p>A patch producer should tell recipients how to apply the patches, so
the first rule of thumb for a patch consumer is to follow the
instructions supplied with the patch.
</p>
<p><acronym>GNU</acronym> <code>diff</code> can analyze files with arbitrarily long lines
and files that end in incomplete lines. However, older versions of
<code>patch</code> cannot patch such files. If you are having trouble
applying such patches, try upgrading to a recent version of <acronym>GNU</acronym>
<code>patch</code>.
</p>
<hr>
<a name="Avoiding-Common-Mistakes"></a>
<div class="header">
<p>
Next: <a href="#Generating-Smaller-Patches" accesskey="n" rel="next">Generating Smaller Patches</a>, Previous: <a href="#Tips-for-Patch-Consumers" accesskey="p" rel="prev">Tips for Patch Consumers</a>, Up: <a href="#Making-Patches" accesskey="u" rel="up">Making Patches</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Avoiding-Common-Mistakes-1"></a>
<h3 class="section">11.3 Avoiding Common Mistakes</h3>
<a name="index-common-mistakes-with-patches"></a>
<a name="index-patch_002c-common-mistakes"></a>
<p>When producing a patch for multiple files, apply <code>diff</code> to
directories whose names do not have slashes. This reduces confusion
when the patch consumer specifies the <samp>-p<var>number</var></samp> option,
since this option can have surprising results when the old and new
file names have different numbers of slashes. For example, do not
send a patch with a header that looks like this:
</p>
<div class="example">
<pre class="example">diff -Naur v2.0.29/prog/README prog/README
--- v2.0.29/prog/README 2002-03-10 23:30:39.942229878 -0800
+++ prog/README 2002-03-17 20:49:32.442260588 -0800
</pre></div>
<p>because the two file names have different numbers of slashes, and
different versions of <code>patch</code> interpret the file names
differently. To avoid confusion, send output that looks like this
instead:
</p>
<div class="example">
<pre class="example">diff -Naur v2.0.29/prog/README v2.0.30/prog/README
--- v2.0.29/prog/README 2002-03-10 23:30:39.942229878 -0800
+++ v2.0.30/prog/README 2002-03-17 20:49:32.442260588 -0800
</pre></div>
<p>Make sure you have specified the file names correctly, either in a
context diff header or with an ‘<samp>Index:</samp>’ line. Take care to not send out
reversed patches, since these make people wonder whether they have
already applied the patch.
</p>
<p>Avoid sending patches that compare backup file names like
<samp>README.orig</samp> or <samp>README~</samp>, since this might confuse
<code>patch</code> into patching a backup file instead of the real file.
Instead, send patches that compare the same base file names in
different directories, e.g. <samp>old/README</samp> and <samp>new/README</samp>.
</p>
<p>To save people from partially applying a patch before other patches that
should have gone before it, you can make the first patch in the patch
file update a file with a name like <samp>patchlevel.h</samp> or
<samp>version.c</samp>, which contains a patch level or version number. If
the input file contains the wrong version number, <code>patch</code> will
complain immediately.
</p>
<p>An even clearer way to prevent this problem is to put a ‘<samp>Prereq:</samp>’
line before the patch. If the leading text in the patch file contains a
line that starts with ‘<samp>Prereq:</samp>’, <code>patch</code> takes the next word
from that line (normally a version number) and checks whether the next
input file contains that word, preceded and followed by either
white space or a newline. If not, <code>patch</code> prompts you for
confirmation before proceeding. This makes it difficult to accidentally
apply patches in the wrong order.
</p>
<hr>
<a name="Generating-Smaller-Patches"></a>
<div class="header">
<p>
Previous: <a href="#Avoiding-Common-Mistakes" accesskey="p" rel="prev">Avoiding Common Mistakes</a>, Up: <a href="#Making-Patches" accesskey="u" rel="up">Making Patches</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Generating-Smaller-Patches-1"></a>
<h3 class="section">11.4 Generating Smaller Patches</h3>
<a name="index-patches_002c-shrinking"></a>
<p>The simplest way to generate a patch is to use ‘<samp>diff -Naur</samp>’
(see <a href="#Tips-for-Patch-Producers">Tips for Patch Producers</a>), but you might be able to reduce
the size of the patch by renaming or removing some files before making
the patch. If the older version of the package contains any files
that the newer version does not, or if any files have been renamed
between the two versions, make a list of <code>rm</code> and <code>mv</code>
commands for the user to execute in the old version directory before
applying the patch. Then run those commands yourself in the scratch
directory.
</p>
<p>If there are any files that you don’t need to include in the patch
because they can easily be rebuilt from other files (for example,
<samp>TAGS</samp> and output from <code>yacc</code> and <code>makeinfo</code>),
exclude them from the patch by giving <code>diff</code> the <samp>-x
<var>pattern</var></samp> option (see <a href="Comparing-Directories.html#Comparing-Directories">Comparing Directories</a>). If you want
your patch to modify a derived file because your recipients lack tools
to build it, make sure that the patch for the derived file follows any
patches for files that it depends on, so that the recipients’ time
stamps will not confuse <code>make</code>.
</p>
<p>Now you can create the patch using ‘<samp>diff -Naur</samp>’. Make sure to
specify the scratch directory first and the newer directory second.
</p>
<p>Add to the top of the patch a note telling the user any <code>rm</code> and
<code>mv</code> commands to run before applying the patch. Then you can
remove the scratch directory.
</p>
<p>You can also shrink the patch size by using fewer lines of context,
but bear in mind that <code>patch</code> typically needs at least two
lines for proper operation when patches do not exactly match the input
files.
</p>
<hr>
<div class="header">
<p>
Previous: <a href="#Avoiding-Common-Mistakes" accesskey="p" rel="prev">Avoiding Common Mistakes</a>, Up: <a href="#Making-Patches" accesskey="u" rel="up">Making Patches</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|