1. Raphael Das Gupta
  2. hgbook-untested


hgbook-untested / en / appA-cmdref.xml

<!-- vim: set filetype=docbkxml shiftwidth=2 autoindent expandtab tw=77 : -->

<appendix id="cmdref">
  <?dbhtml filename="command-reference.html"?>
<title>Command reference</title>

<para id="x_653">\cmdref{add}{add files at the next commit}

<para id="x_654">\cmdref{diff}{print changes in history or working directory}</para>

<para id="x_655">Show differences between revisions for the specified files or
directories, using the unified diff format.  For a description of the
unified diff format, see <xref linkend="sec:mq:patch"/>.</para>

<para id="x_656">By default, this command does not print diffs for files that Mercurial
considers to contain binary data.  To control this behavior, see the
<option role="hg-opt-diff">-a</option> and <option role="hg-opt-diff">--git</option> options.</para>

<para id="x_657">\loptref{diff}{nodates}</para>

<para id="x_658">Omit date and time information when printing diff headers.</para>

<para id="x_659">\optref{diff}{B}{ignore-blank-lines}</para>

<para id="x_65a">Do not print changes that only insert or delete blank lines.  A line
that contains only whitespace is not considered blank.

<para id="x_65b">\optref{diff}{I}{include}

<para id="x_65c">Include files and directories whose names match the given patterns.

<para id="x_65d">\optref{diff}{X}{exclude}

<para id="x_65e">Exclude files and directories whose names match the given patterns.

<para id="x_65f">\optref{diff}{a}{text}

<para id="x_660">If this option is not specified, <command role="hg-cmd">hg diff</command> will refuse to print
diffs for files that it detects as binary. Specifying <option role="hg-opt-diff">-a</option>
forces <command role="hg-cmd">hg diff</command> to treat all files as text, and generate diffs for
all of them.

<para id="x_661">This option is useful for files that are <quote>mostly text</quote> but have a
few embedded NUL characters.  If you use it on files that contain a
lot of binary data, its output will be incomprehensible.

<para id="x_662">\optref{diff}{b}{ignore-space-change}

<para id="x_663">Do not print a line if the only change to that line is in the amount
of white space it contains.

<para id="x_664">\optref{diff}{g}{git}

<para id="x_665">Print <command>git</command>-compatible diffs.  XXX reference a format

<para id="x_666">\optref{diff}{p}{show-function}

<para id="x_667">Display the name of the enclosing function in a hunk header, using a
simple heuristic.  This functionality is enabled by default, so the
<option role="hg-opt-diff">-p</option> option has no effect unless you change the value of
the <envar role="rc-item-diff">showfunc</envar> config item, as in the following example.</para>

<!-- &interaction.cmdref.diff-p; -->

<para id="x_668">\optref{diff}{r}{rev}

<para id="x_669">Specify one or more revisions to compare.  The <command role="hg-cmd">hg diff</command> command
accepts up to two <option role="hg-opt-diff">-r</option> options to specify the revisions to

<listitem><para id="x_66a">Display the differences between the parent revision of the
  working directory and the working directory.
<listitem><para id="x_66b">Display the differences between the specified changeset and the
  working directory.
<listitem><para id="x_66c">Display the differences between the two specified changesets.

<para id="x_66d">You can specify two revisions using either two <option role="hg-opt-diff">-r</option>
options or revision range notation.  For example, the two revision
specifications below are equivalent.
<programlisting>hg diff -r 10 -r 20
hg diff -r10:20</programlisting>

<para id="x_66e">When you provide two revisions, Mercurial treats the order of those
revisions as significant.  Thus, <command role="hg-cmd">hg diff -r10:20</command> will
produce a diff that will transform files from their contents as of
revision 10 to their contents as of revision 20, while
<command role="hg-cmd">hg diff -r20:10</command> means the opposite: the diff that will
transform files from their revision 20 contents to their revision 10
contents.  You cannot reverse the ordering in this way if you are
diffing against the working directory.

<para id="x_66f">\optref{diff}{w}{ignore-all-space}

<para id="x_670">\cmdref{version}{print version and copyright information}

<para id="x_671">This command displays the version of Mercurial you are running, and
its copyright license.  There are four kinds of version string that
you may see.
<listitem><para id="x_672">The string <quote><literal>unknown</literal></quote>. This version of Mercurial was
  not built in a Mercurial repository, and cannot determine its own
<listitem><para id="x_673">A short numeric string, such as <quote><literal>1.1</literal></quote>. This is a
  build of a revision of Mercurial that was identified by a specific
  tag in the repository where it was built.  (This doesn't necessarily
  mean that you're running an official release; someone else could
  have added that tag to any revision in the repository where they
  built Mercurial.)
<listitem><para id="x_674">A hexadecimal string, such as <quote><literal>875489e31abe</literal></quote>.  This
  is a build of the given revision of Mercurial.
<listitem><para id="x_675">A hexadecimal string followed by a date, such as
  <quote><literal>875489e31abe+20070205</literal></quote>.  This is a build of the given
  revision of Mercurial, where the build repository contained some
  local changes that had not been committed.

<title>Tips and tricks</title>

<sect3 id="cmdref:diff-vs-status">
<title>Why do the results of <command role="hg-cmd">hg diff</command> and <command role="hg-cmd">hg status</command> differ?</title>

<para id="x_676">When you run the <command role="hg-cmd">hg status</command> command, you'll see a list of files
that Mercurial will record changes for the next time you perform a
commit.  If you run the <command role="hg-cmd">hg diff</command> command, you may notice that it
prints diffs for only a <emphasis>subset</emphasis> of the files that <command role="hg-cmd">hg status</command>
listed.  There are two possible reasons for this.

<para id="x_677">The first is that <command role="hg-cmd">hg status</command> prints some kinds of modifications
that <command role="hg-cmd">hg diff</command> doesn't normally display.  The <command role="hg-cmd">hg diff</command> command
normally outputs unified diffs, which don't have the ability to
represent some changes that Mercurial can track.  Most notably,
traditional diffs can't represent a change in whether or not a file is
executable, but Mercurial records this information.

<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
display <command>git</command>-compatible diffs that <emphasis>can</emphasis> display this
extra information.

<para id="x_679">The second possible reason that <command role="hg-cmd">hg diff</command> might be printing diffs
for a subset of the files displayed by <command role="hg-cmd">hg status</command> is that if you
invoke it without any arguments, <command role="hg-cmd">hg diff</command> prints diffs against the
first parent of the working directory.  If you have run <command role="hg-cmd">hg merge</command>
to merge two changesets, but you haven't yet committed the results of
the merge, your working directory has two parents (use <command role="hg-cmd">hg parents</command>
to see them).  While <command role="hg-cmd">hg status</command> prints modifications relative to
<emphasis>both</emphasis> parents after an uncommitted merge, <command role="hg-cmd">hg diff</command> still
operates relative only to the first parent.  You can get it to print
diffs relative to the second parent by specifying that parent with the
<option role="hg-opt-diff">-r</option> option.  There is no way to print diffs relative to
both parents.

<title>Generating safe binary diffs</title>

<para id="x_67a">If you use the <option role="hg-opt-diff">-a</option> option to force Mercurial to print
diffs of files that are either <quote>mostly text</quote> or contain lots of
binary data, those diffs cannot subsequently be applied by either
Mercurial's <command role="hg-cmd">hg import</command> command or the system's <command>patch</command>

<para id="x_67b">If you want to generate a diff of a binary file that is safe to use as
input for <command role="hg-cmd">hg import</command>, use the <command role="hg-cmd">hg diff</command>{--git} option when you
generate the patch.  The system <command>patch</command> command cannot handle
binary patches at all.


local variables: 
sgml-parent-document: ("00book.xml" "book" "appendix")