Mercurial > hgbook
annotate en/cmdref.tex @ 132:e1e2f3e0256a
Start command reference, with the diff command.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Thu, 28 Dec 2006 16:45:56 -0800 |
parents | |
children | 1e013fbe35f7 |
rev | line source |
---|---|
132
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1 \chapter{Command reference} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2 \label{cmdref} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
3 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
4 \cmdref{diff} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
5 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
6 Show differences between revisions for the specified files or |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
7 directories, using the unified diff format. For a description of the |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
8 unified diff format, see section~\ref{sec:mq:patch}. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
9 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
10 \optref{diff}{-r}{--rev} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
11 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
12 Specify a revision to compare. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
13 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
14 \optref{diff}{-a}{--text} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
15 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
16 If this option is not specified, \hgcmd{diff} will refuse to print |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
17 diffs for files that it detects as binary. Specifying \hgopt{diff}{-a} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
18 forces \hgcmd{diff} to treat all files as text, and generate diffs for |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
19 all of them. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
20 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
21 This option is useful for files that are ``mostly text'' but have a |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
22 few embedded NUL characters. If you use it on files that are really |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
23 binary, its output will be incomprehensible. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
24 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
25 \subsection{Specifying revisions} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
26 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
27 The \hgcmd{diff} command accepts up to two \hgopt{diff}{-r} options to |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
28 specify the revisions to compare. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
29 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
30 \begin{enumerate} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
31 \setcounter{enumi}{0} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
32 \item Display the differences between the parent of the working |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
33 directory and the working directory. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
34 \item Display the differences between the specified changeset and the |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
35 working directory. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
36 \item Display the differences between the two specified changesets. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
37 \end{enumerate} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
38 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
39 You can specify two revisions using either two \hgopt{diff}{-r} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
40 options or revision range notation. For example, the two revision |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
41 specifications below are equivalent. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
42 \begin{codesample2} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
43 hg diff -r 10 -r 20 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
44 hg diff -r10:20 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
45 \end{codesample2} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
46 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
47 When you provide two revisions, Mercurial treats the order of those |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
48 revisions as significant. Thus, \hgcmdargs{diff}{-r10:20} will |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
49 produce a diff that will transform files from their contents as of |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
50 revision~10 to their contents as of revision~20, while |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
51 \hgcmdargs{diff}{-r20:10} means the opposite: the diff that will |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
52 transform files from their revision~20 contents to their revision~10 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
53 contents. You cannot reverse the ordering in this way if you are |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
54 diffing against the working directory. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
55 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
56 \subsection{Why do the results of \hgcmd{diff} and \hgcmd{status} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
57 differ?} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
58 \label{cmdref:diff-vs-status} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
59 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
60 When you run the \hgcmd{status} command, you'll see a list of files |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
61 that Mercurial will record changes for the next time you perform a |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
62 commit. If you run the \hgcmd{diff} command, you may notice that it |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
63 prints diffs for only a \emph{subset} of the files that \hgcmd{status} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
64 listed. There are two possible reasons for this. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
65 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
66 The first is that \hgcmd{status} prints some kinds of modifications |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
67 that \hgcmd{diff} doesn't normally display. The \hgcmd{diff} command |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
68 normally outputs unified diffs, which don't have the ability to |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
69 represent some changes that Mercurial can track. Most notably, |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
70 traditional diffs can't represent a change in whether or not a file is |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
71 executable, but Mercurial records this information. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
72 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
73 If you use the \hgopt{diff}{--git} option to \hgcmd{diff}, it will |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
74 display \command{git}-compatible diffs that \emph{can} display this |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
75 extra information. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
76 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
77 The second possible reason that \hgcmd{diff} might be printing diffs |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
78 for a subset of the files displayed by \hgcmd{status} is that if you |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
79 invoke it without any arguments, \hgcmd{diff} prints diffs against the |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
80 first parent of the working directory. If you have run \hgcmd{merge} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
81 to merge two changesets, but you haven't yet committed the results of |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
82 the merge, your working directory has two parents (use \hgcmd{parents} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
83 to see them). While \hgcmd{status} prints modifications relative to |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
84 \emph{both} parents after an uncommitted merge, \hgcmd{diff} still |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
85 operates relative only to the first parent. You can get it to print |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
86 diffs relative to the second parent by specifying that parent with the |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
87 \hgopt{diff}{-r} option. There is no way to print diffs relative to |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
88 both parents. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
89 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
90 \subsection{Generating safe binary diffs} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
91 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
92 If you use the \hgopt{diff}{-a} option to force Mercurial to print |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
93 diffs of files that are either ``mostly text'' or contain lots of |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
94 binary data, those diffs cannot subsequently be applied by either |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
95 Mercurial's \hgcmd{import} command or the system's \command{patch} |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
96 command. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
97 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
98 If you want to generate a diff of a binary file that is safe to use as |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
99 input for \hgcmd{import}, use the \hgcmd{diff}{--git} option when you |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
100 generate the patch. The system \command{patch} command cannot handle |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
101 binary patches at all. |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
102 |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
103 %%% Local Variables: |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
104 %%% mode: latex |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
105 %%% TeX-master: "00book" |
e1e2f3e0256a
Start command reference, with the diff command.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
106 %%% End: |