rev |
line source |
bos@559
|
1 <!-- vim: set filetype=docbkxml shiftwidth=2 autoindent expandtab tw=77 : -->
|
bos@559
|
2
|
bos@559
|
3 <appendix id="cmdref">
|
bos@559
|
4 <title>Command reference</title>
|
bos@559
|
5
|
dongsheng@650
|
6 <para id="x_653">\cmdref{add}{add files at the next commit}
|
bos@133
|
7 \optref{add}{I}{include}
|
bos@133
|
8 \optref{add}{X}{exclude}
|
bos@559
|
9 \optref{add}{n}{dry-run}</para>
|
bos@559
|
10
|
dongsheng@650
|
11 <para id="x_654">\cmdref{diff}{print changes in history or working directory}</para>
|
dongsheng@650
|
12
|
dongsheng@650
|
13 <para id="x_655">Show differences between revisions for the specified files or
|
bos@132
|
14 directories, using the unified diff format. For a description of the
|
dongsheng@625
|
15 unified diff format, see section <xref linkend="sec.mq.patch"/>.</para>
|
bos@559
|
16
|
dongsheng@650
|
17 <para id="x_656">By default, this command does not print diffs for files that Mercurial
|
bos@133
|
18 considers to contain binary data. To control this behaviour, see the
|
bos@559
|
19 <option role="hg-opt-diff">-a</option> and <option role="hg-opt-diff">--git</option> options.</para>
|
bos@559
|
20
|
bos@559
|
21 <sect2>
|
bos@559
|
22 <title>Options</title>
|
bos@559
|
23
|
dongsheng@650
|
24 <para id="x_657">\loptref{diff}{nodates}</para>
|
dongsheng@650
|
25
|
dongsheng@650
|
26 <para id="x_658">Omit date and time information when printing diff headers.</para>
|
dongsheng@650
|
27
|
dongsheng@650
|
28 <para id="x_659">\optref{diff}{B}{ignore-blank-lines}</para>
|
dongsheng@650
|
29
|
dongsheng@650
|
30 <para id="x_65a">Do not print changes that only insert or delete blank lines. A line
|
bos@133
|
31 that contains only whitespace is not considered blank.
|
bos@559
|
32 </para>
|
bos@559
|
33
|
dongsheng@650
|
34 <para id="x_65b">\optref{diff}{I}{include}
|
dongsheng@650
|
35 </para>
|
dongsheng@650
|
36
|
dongsheng@650
|
37 <para id="x_65c">Include files and directories whose names match the given patterns.
|
dongsheng@650
|
38 </para>
|
dongsheng@650
|
39
|
dongsheng@650
|
40 <para id="x_65d">\optref{diff}{X}{exclude}
|
dongsheng@650
|
41 </para>
|
dongsheng@650
|
42
|
dongsheng@650
|
43 <para id="x_65e">Exclude files and directories whose names match the given patterns.
|
dongsheng@650
|
44 </para>
|
dongsheng@650
|
45
|
dongsheng@650
|
46 <para id="x_65f">\optref{diff}{a}{text}
|
dongsheng@650
|
47 </para>
|
dongsheng@650
|
48
|
dongsheng@650
|
49 <para id="x_660">If this option is not specified, <command role="hg-cmd">hg diff</command> will refuse to print
|
bos@559
|
50 diffs for files that it detects as binary. Specifying <option role="hg-opt-diff">-a</option>
|
bos@559
|
51 forces <command role="hg-cmd">hg diff</command> to treat all files as text, and generate diffs for
|
bos@132
|
52 all of them.
|
bos@559
|
53 </para>
|
bos@559
|
54
|
dongsheng@650
|
55 <para id="x_661">This option is useful for files that are <quote>mostly text</quote> but have a
|
bos@133
|
56 few embedded NUL characters. If you use it on files that contain a
|
bos@133
|
57 lot of binary data, its output will be incomprehensible.
|
bos@559
|
58 </para>
|
bos@559
|
59
|
dongsheng@650
|
60 <para id="x_662">\optref{diff}{b}{ignore-space-change}
|
dongsheng@650
|
61 </para>
|
dongsheng@650
|
62
|
dongsheng@650
|
63 <para id="x_663">Do not print a line if the only change to that line is in the amount
|
bos@133
|
64 of white space it contains.
|
bos@559
|
65 </para>
|
bos@559
|
66
|
dongsheng@650
|
67 <para id="x_664">\optref{diff}{g}{git}
|
dongsheng@650
|
68 </para>
|
dongsheng@650
|
69
|
dongsheng@650
|
70 <para id="x_665">Print <command>git</command>-compatible diffs. XXX reference a format
|
bos@133
|
71 description.
|
bos@559
|
72 </para>
|
bos@559
|
73
|
dongsheng@650
|
74 <para id="x_666">\optref{diff}{p}{show-function}
|
dongsheng@650
|
75 </para>
|
dongsheng@650
|
76
|
dongsheng@650
|
77 <para id="x_667">Display the name of the enclosing function in a hunk header, using a
|
bos@133
|
78 simple heuristic. This functionality is enabled by default, so the
|
bos@559
|
79 <option role="hg-opt-diff">-p</option> option has no effect unless you change the value of
|
bos@559
|
80 the <envar role="rc-item-diff">showfunc</envar> config item, as in the following example.</para>
|
bos@559
|
81
|
bos@559
|
82 <!-- &interaction.cmdref.diff-p; -->
|
bos@559
|
83
|
dongsheng@650
|
84 <para id="x_668">\optref{diff}{r}{rev}
|
dongsheng@650
|
85 </para>
|
dongsheng@650
|
86
|
dongsheng@650
|
87 <para id="x_669">Specify one or more revisions to compare. The <command role="hg-cmd">hg diff</command> command
|
bos@559
|
88 accepts up to two <option role="hg-opt-diff">-r</option> options to specify the revisions to
|
bos@133
|
89 compare.
|
bos@559
|
90 </para>
|
bos@559
|
91
|
bos@559
|
92 <orderedlist>
|
dongsheng@650
|
93 <listitem><para id="x_66a">Display the differences between the parent revision of the
|
bos@133
|
94 working directory and the working directory.
|
bos@559
|
95 </para>
|
bos@559
|
96 </listitem>
|
dongsheng@650
|
97 <listitem><para id="x_66b">Display the differences between the specified changeset and the
|
bos@132
|
98 working directory.
|
bos@559
|
99 </para>
|
bos@559
|
100 </listitem>
|
dongsheng@650
|
101 <listitem><para id="x_66c">Display the differences between the two specified changesets.
|
bos@559
|
102 </para>
|
bos@559
|
103 </listitem></orderedlist>
|
bos@559
|
104
|
dongsheng@650
|
105 <para id="x_66d">You can specify two revisions using either two <option role="hg-opt-diff">-r</option>
|
bos@132
|
106 options or revision range notation. For example, the two revision
|
bos@132
|
107 specifications below are equivalent.
|
bos@559
|
108 </para>
|
bos@559
|
109 <programlisting>hg diff -r 10 -r 20
|
bos@559
|
110 hg diff -r10:20</programlisting>
|
bos@559
|
111
|
dongsheng@650
|
112 <para id="x_66e">When you provide two revisions, Mercurial treats the order of those
|
bos@559
|
113 revisions as significant. Thus, <command role="hg-cmd">hg diff -r10:20</command> will
|
bos@132
|
114 produce a diff that will transform files from their contents as of
|
bos@559
|
115 revision 10 to their contents as of revision 20, while
|
bos@559
|
116 <command role="hg-cmd">hg diff -r20:10</command> means the opposite: the diff that will
|
bos@559
|
117 transform files from their revision 20 contents to their revision 10
|
bos@132
|
118 contents. You cannot reverse the ordering in this way if you are
|
bos@132
|
119 diffing against the working directory.
|
bos@559
|
120 </para>
|
bos@559
|
121
|
dongsheng@650
|
122 <para id="x_66f">\optref{diff}{w}{ignore-all-space}
|
dongsheng@650
|
123 </para>
|
dongsheng@650
|
124
|
dongsheng@650
|
125 <para id="x_670">\cmdref{version}{print version and copyright information}
|
dongsheng@650
|
126 </para>
|
dongsheng@650
|
127
|
dongsheng@650
|
128 <para id="x_671">This command displays the version of Mercurial you are running, and
|
bos@133
|
129 its copyright license. There are four kinds of version string that
|
bos@133
|
130 you may see.
|
bos@559
|
131 </para>
|
bos@559
|
132 <itemizedlist>
|
dongsheng@650
|
133 <listitem><para id="x_672">The string <quote><literal>unknown</literal></quote>. This version of Mercurial was
|
bos@133
|
134 not built in a Mercurial repository, and cannot determine its own
|
bos@133
|
135 version.
|
bos@559
|
136 </para>
|
bos@559
|
137 </listitem>
|
dongsheng@650
|
138 <listitem><para id="x_673">A short numeric string, such as <quote><literal>1.1</literal></quote>. This is a
|
bos@133
|
139 build of a revision of Mercurial that was identified by a specific
|
bos@133
|
140 tag in the repository where it was built. (This doesn't necessarily
|
bos@133
|
141 mean that you're running an official release; someone else could
|
bos@133
|
142 have added that tag to any revision in the repository where they
|
bos@133
|
143 built Mercurial.)
|
bos@559
|
144 </para>
|
bos@559
|
145 </listitem>
|
dongsheng@650
|
146 <listitem><para id="x_674">A hexadecimal string, such as <quote><literal>875489e31abe</literal></quote>. This
|
bos@133
|
147 is a build of the given revision of Mercurial.
|
bos@559
|
148 </para>
|
bos@559
|
149 </listitem>
|
dongsheng@650
|
150 <listitem><para id="x_675">A hexadecimal string followed by a date, such as
|
bos@559
|
151 <quote><literal>875489e31abe+20070205</literal></quote>. This is a build of the given
|
bos@133
|
152 revision of Mercurial, where the build repository contained some
|
bos@133
|
153 local changes that had not been committed.
|
bos@559
|
154 </para>
|
bos@559
|
155 </listitem></itemizedlist>
|
bos@559
|
156
|
bos@559
|
157 </sect2>
|
bos@559
|
158 <sect2>
|
bos@559
|
159 <title>Tips and tricks</title>
|
bos@559
|
160
|
dongsheng@625
|
161 <sect3 id="cmdref.diff-vs-status">
|
bos@559
|
162 <title>Why do the results of <command role="hg-cmd">hg diff</command> and <command role="hg-cmd">hg status</command> differ?</title>
|
bos@559
|
163
|
dongsheng@650
|
164 <para id="x_676">When you run the <command role="hg-cmd">hg status</command> command, you'll see a list of files
|
bos@132
|
165 that Mercurial will record changes for the next time you perform a
|
bos@559
|
166 commit. If you run the <command role="hg-cmd">hg diff</command> command, you may notice that it
|
bos@559
|
167 prints diffs for only a <emphasis>subset</emphasis> of the files that <command role="hg-cmd">hg status</command>
|
bos@132
|
168 listed. There are two possible reasons for this.
|
bos@559
|
169 </para>
|
bos@559
|
170
|
dongsheng@650
|
171 <para id="x_677">The first is that <command role="hg-cmd">hg status</command> prints some kinds of modifications
|
bos@559
|
172 that <command role="hg-cmd">hg diff</command> doesn't normally display. The <command role="hg-cmd">hg diff</command> command
|
bos@132
|
173 normally outputs unified diffs, which don't have the ability to
|
bos@132
|
174 represent some changes that Mercurial can track. Most notably,
|
bos@132
|
175 traditional diffs can't represent a change in whether or not a file is
|
bos@132
|
176 executable, but Mercurial records this information.
|
bos@559
|
177 </para>
|
bos@559
|
178
|
dongsheng@650
|
179 <para id="x_678">If you use the <option role="hg-opt-diff">--git</option> option to <command role="hg-cmd">hg diff</command>, it will
|
bos@559
|
180 display <command>git</command>-compatible diffs that <emphasis>can</emphasis> display this
|
bos@132
|
181 extra information.
|
bos@559
|
182 </para>
|
bos@559
|
183
|
dongsheng@650
|
184 <para id="x_679">The second possible reason that <command role="hg-cmd">hg diff</command> might be printing diffs
|
bos@559
|
185 for a subset of the files displayed by <command role="hg-cmd">hg status</command> is that if you
|
bos@559
|
186 invoke it without any arguments, <command role="hg-cmd">hg diff</command> prints diffs against the
|
bos@559
|
187 first parent of the working directory. If you have run <command role="hg-cmd">hg merge</command>
|
bos@132
|
188 to merge two changesets, but you haven't yet committed the results of
|
bos@559
|
189 the merge, your working directory has two parents (use <command role="hg-cmd">hg parents</command>
|
bos@559
|
190 to see them). While <command role="hg-cmd">hg status</command> prints modifications relative to
|
bos@559
|
191 <emphasis>both</emphasis> parents after an uncommitted merge, <command role="hg-cmd">hg diff</command> still
|
bos@132
|
192 operates relative only to the first parent. You can get it to print
|
bos@132
|
193 diffs relative to the second parent by specifying that parent with the
|
bos@559
|
194 <option role="hg-opt-diff">-r</option> option. There is no way to print diffs relative to
|
bos@132
|
195 both parents.
|
bos@559
|
196 </para>
|
bos@559
|
197
|
bos@559
|
198 </sect3>
|
bos@559
|
199 <sect3>
|
bos@559
|
200 <title>Generating safe binary diffs</title>
|
bos@559
|
201
|
dongsheng@650
|
202 <para id="x_67a">If you use the <option role="hg-opt-diff">-a</option> option to force Mercurial to print
|
bos@559
|
203 diffs of files that are either <quote>mostly text</quote> or contain lots of
|
bos@132
|
204 binary data, those diffs cannot subsequently be applied by either
|
bos@559
|
205 Mercurial's <command role="hg-cmd">hg import</command> command or the system's <command>patch</command>
|
bos@559
|
206 command.
|
bos@559
|
207 </para>
|
bos@559
|
208
|
dongsheng@650
|
209 <para id="x_67b">If you want to generate a diff of a binary file that is safe to use as
|
bos@559
|
210 input for <command role="hg-cmd">hg import</command>, use the <command role="hg-cmd">hg diff</command>{--git} option when you
|
bos@559
|
211 generate the patch. The system <command>patch</command> command cannot handle
|
bos@132
|
212 binary patches at all.
|
bos@559
|
213 </para>
|
bos@559
|
214
|
bos@559
|
215 </sect3>
|
bos@559
|
216 </sect2>
|
bos@559
|
217 </appendix>
|
bos@559
|
218
|
bos@559
|
219 <!--
|
bos@559
|
220 local variables:
|
bos@559
|
221 sgml-parent-document: ("00book.xml" "book" "appendix")
|
bos@559
|
222 end:
|
bos@559
|
223 -->
|