annotate en/tour-merge.tex @ 540:4e0684e824e1

translated up to the tutorial on using hooks
author jerojasro@abu.no-ip.org
date Mon, 08 Dec 2008 11:16:54 -0500
parents e602d061c078
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
481
e602d061c078 reverted translation on wrong file. Silly sleepy me
Javier Rojas <jerojasro@devnull.li>
parents: 479
diff changeset
1 \chapter{A tour of Mercurial: merging work}
95
47ea206351d5 Split tour into two sections.
Bryan O'Sullivan <bos@serpentine.com>
parents: 94
diff changeset
2 \label{chap:tour-merge}
94
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
3
481
e602d061c078 reverted translation on wrong file. Silly sleepy me
Javier Rojas <jerojasro@devnull.li>
parents: 479
diff changeset
4 We've now covered cloning a repository, making changes in a
e602d061c078 reverted translation on wrong file. Silly sleepy me
Javier Rojas <jerojasro@devnull.li>
parents: 479
diff changeset
5 repository, and pulling or pushing changes from one repository into
e602d061c078 reverted translation on wrong file. Silly sleepy me
Javier Rojas <jerojasro@devnull.li>
parents: 479
diff changeset
6 another. Our next step is \emph{merging} changes from separate
e602d061c078 reverted translation on wrong file. Silly sleepy me
Javier Rojas <jerojasro@devnull.li>
parents: 479
diff changeset
7 repositories.
94
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
8
95
47ea206351d5 Split tour into two sections.
Bryan O'Sullivan <bos@serpentine.com>
parents: 94
diff changeset
9 \section{Merging streams of work}
47ea206351d5 Split tour into two sections.
Bryan O'Sullivan <bos@serpentine.com>
parents: 94
diff changeset
10
94
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
11 Merging is a fundamental part of working with a distributed revision
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
12 control tool.
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
13 \begin{itemize}
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
14 \item Alice and Bob each have a personal copy of a repository for a
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
15 project they're collaborating on. Alice fixes a bug in her
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
16 repository; Bob adds a new feature in his. They want the shared
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
17 repository to contain both the bug fix and the new feature.
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
18 \item I frequently work on several different tasks for a single
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
19 project at once, each safely isolated in its own repository.
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
20 Working this way means that I often need to merge one piece of my
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
21 own work with another.
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
22 \end{itemize}
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
23
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
24 Because merging is such a common thing to need to do, Mercurial makes
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
25 it easy. Let's walk through the process. We'll begin by cloning yet
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
26 another repository (see how often they spring up?) and making a change
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
27 in it.
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
28 \interaction{tour.merge.clone}
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
29 We should now have two copies of \filename{hello.c} with different
99
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
30 contents. The histories of the two repositories have also diverged,
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
31 as illustrated in figure~\ref{fig:tour-merge:sep-repos}.
94
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
32 \interaction{tour.merge.cat}
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
33
99
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
34 \begin{figure}[ht]
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
35 \centering
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
36 \grafix{tour-merge-sep-repos}
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
37 \caption{Divergent recent histories of the \dirname{my-hello} and
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
38 \dirname{my-new-hello} repositories}
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
39 \label{fig:tour-merge:sep-repos}
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
40 \end{figure}
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
41
94
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
42 We already know that pulling changes from our \dirname{my-hello}
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
43 repository will have no effect on the working directory.
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
44 \interaction{tour.merge.pull}
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
45 However, the \hgcmd{pull} command says something about ``heads''.
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
46
102
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
47 \subsection{Head changesets}
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
48
99
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
49 A head is a change that has no descendants, or children, as they're
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
50 also known. The tip revision is thus a head, because the newest
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
51 revision in a repository doesn't have any children, but a repository
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
52 can contain more than one head.
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
53
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
54 \begin{figure}[ht]
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
55 \centering
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
56 \grafix{tour-merge-pull}
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
57 \caption{Repository contents after pulling from \dirname{my-hello} into
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
58 \dirname{my-new-hello}}
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
59 \label{fig:tour-merge:pull}
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
60 \end{figure}
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
61
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
62 In figure~\ref{fig:tour-merge:pull}, you can see the effect of the
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
63 pull from \dirname{my-hello} into \dirname{my-new-hello}. The history
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
64 that was already present in \dirname{my-new-hello} is untouched, but a
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
65 new revision has been added. By referring to
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
66 figure~\ref{fig:tour-merge:sep-repos}, we can see that the
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
67 \emph{changeset ID} remains the same in the new repository, but the
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
68 \emph{revision number} has changed. (This, incidentally, is a fine
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
69 example of why it's not safe to use revision numbers when discussing
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
70 changesets.) We can view the heads in a repository using the
06383f9e46e4 More graphics.
Bryan O'Sullivan <bos@serpentine.com>
parents: 95
diff changeset
71 \hgcmd{heads} command.
94
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
72 \interaction{tour.merge.heads}
102
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
73
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
74 \subsection{Performing the merge}
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
75
94
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
76 What happens if we try to use the normal \hgcmd{update} command to
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
77 update to the new tip?
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
78 \interaction{tour.merge.update}
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
79 Mercurial is telling us that the \hgcmd{update} command won't do a
100
272146fab009 Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents: 99
diff changeset
80 merge; it won't update the working directory when it thinks we might
272146fab009 Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents: 99
diff changeset
81 be wanting to do a merge, unless we force it to do so. Instead, we
272146fab009 Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents: 99
diff changeset
82 use the \hgcmd{merge} command to merge the two heads.
94
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
83 \interaction{tour.merge.merge}
100
272146fab009 Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents: 99
diff changeset
84
272146fab009 Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents: 99
diff changeset
85 \begin{figure}[ht]
272146fab009 Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents: 99
diff changeset
86 \centering
272146fab009 Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents: 99
diff changeset
87 \grafix{tour-merge-merge}
272146fab009 Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents: 99
diff changeset
88 \caption{Working directory and repository during merge, and
272146fab009 Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents: 99
diff changeset
89 following commit}
272146fab009 Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents: 99
diff changeset
90 \label{fig:tour-merge:merge}
272146fab009 Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents: 99
diff changeset
91 \end{figure}
272146fab009 Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents: 99
diff changeset
92
94
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
93 This updates the working directory so that it contains changes from
100
272146fab009 Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents: 99
diff changeset
94 \emph{both} heads, which is reflected in both the output of
272146fab009 Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents: 99
diff changeset
95 \hgcmd{parents} and the contents of \filename{hello.c}.
94
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
96 \interaction{tour.merge.parents}
102
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
97
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
98 \subsection{Committing the results of the merge}
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
99
94
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
100 Whenever we've done a merge, \hgcmd{parents} will display two parents
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
101 until we \hgcmd{commit} the results of the merge.
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
102 \interaction{tour.merge.commit}
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
103 We now have a new tip revision; notice that it has \emph{both} of
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
104 our former heads as its parents. These are the same revisions that
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
105 were previously displayed by \hgcmd{parents}.
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
106 \interaction{tour.merge.tip}
101
321732566ac1 A few bits of terminological clarification.
Bryan O'Sullivan <bos@serpentine.com>
parents: 100
diff changeset
107 In figure~\ref{fig:tour-merge:merge}, you can see a representation of
321732566ac1 A few bits of terminological clarification.
Bryan O'Sullivan <bos@serpentine.com>
parents: 100
diff changeset
108 what happens to the working directory during the merge, and how this
321732566ac1 A few bits of terminological clarification.
Bryan O'Sullivan <bos@serpentine.com>
parents: 100
diff changeset
109 affects the repository when the commit happens. During the merge, the
321732566ac1 A few bits of terminological clarification.
Bryan O'Sullivan <bos@serpentine.com>
parents: 100
diff changeset
110 working directory has two parent changesets, and these become the
321732566ac1 A few bits of terminological clarification.
Bryan O'Sullivan <bos@serpentine.com>
parents: 100
diff changeset
111 parents of the new changeset.
94
0b97b0bdc830 Basic merge coverage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 93
diff changeset
112
102
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
113 \section{Merging conflicting changes}
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
114
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
115 Most merges are simple affairs, but sometimes you'll find yourself
103
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
116 merging changes where each modifies the same portions of the same
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
117 files. Unless both modifications are identical, this results in a
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
118 \emph{conflict}, where you have to decide how to reconcile the
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
119 different changes into something coherent.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
120
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
121 \begin{figure}[ht]
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
122 \centering
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
123 \grafix{tour-merge-conflict}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
124 \caption{Conflicting changes to a document}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
125 \label{fig:tour-merge:conflict}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
126 \end{figure}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
127
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
128 Figure~\ref{fig:tour-merge:conflict} illustrates an instance of two
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
129 conflicting changes to a document. We started with a single version
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
130 of the file; then we made some changes; while someone else made
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
131 different changes to the same text. Our task in resolving the
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
132 conflicting changes is to decide what the file should look like.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
133
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
134 Mercurial doesn't have a built-in facility for handling conflicts.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
135 Instead, it runs an external program called \command{hgmerge}. This
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
136 is a shell script that is bundled with Mercurial; you can change it to
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
137 behave however you please. What it does by default is try to find one
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
138 of several different merging tools that are likely to be installed on
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
139 your system. It first tries a few fully automatic merging tools; if
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
140 these don't succeed (because the resolution process requires human
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
141 guidance) or aren't present, the script tries a few different
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
142 graphical merging tools.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
143
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
144 It's also possible to get Mercurial to run another program or script
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
145 instead of \command{hgmerge}, by setting the \envar{HGMERGE}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
146 environment variable to the name of your preferred program.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
147
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
148 \subsection{Using a graphical merge tool}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
149
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
150 My preferred graphical merge tool is \command{kdiff3}, which I'll use
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
151 to describe the features that are common to graphical file merging
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
152 tools. You can see a screenshot of \command{kdiff3} in action in
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
153 figure~\ref{fig:tour-merge:kdiff3}. The kind of merge it is
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
154 performing is called a \emph{three-way merge}, because there are three
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
155 different versions of the file of interest to us. The tool thus
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
156 splits the upper portion of the window into three panes:
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
157 \begin{itemize}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
158 \item At the left is the \emph{base} version of the file, i.e.~the
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
159 most recent version from which the two versions we're trying to
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
160 merge are descended.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
161 \item In the middle is ``our'' version of the file, with the contents
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
162 that we modified.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
163 \item On the right is ``their'' version of the file, the one that
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
164 from the changeset that we're trying to merge with.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
165 \end{itemize}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
166 In the pane below these is the current \emph{result} of the merge.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
167 Our task is to replace all of the red text, which indicates unresolved
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
168 conflicts, with some sensible merger of the ``ours'' and ``theirs''
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
169 versions of the file.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
170
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
171 All four of these panes are \emph{locked together}; if we scroll
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
172 vertically or horizontally in any of them, the others are updated to
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
173 display the corresponding sections of their respective files.
102
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
174
103
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
175 \begin{figure}[ht]
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
176 \centering
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
177 \grafix{kdiff3}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
178 \caption{Using \command{kdiff3} to merge versions of a file}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
179 \label{fig:tour-merge:kdiff3}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
180 \end{figure}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
181
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
182 For each conflicting portion of the file, we can choose to resolve
257
d9d29e7cf5bd fix a couple of over-zealous 'h' key typos
Michael Rowe <mrowe@mojain.com>
parents: 224
diff changeset
183 the conflict using some combination of text from the base version,
103
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
184 ours, or theirs. We can also manually edit the merged file at any
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
185 time, in case we need to make further modifications.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
186
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
187 There are \emph{many} file merging tools available, too many to cover
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
188 here. They vary in which platforms they are available for, and in
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
189 their particular strengths and weaknesses. Most are tuned for merging
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
190 files containing plain text, while a few are aimed at specialised file
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
191 formats (generally XML).
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
192
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
193 \subsection{A worked example}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
194
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
195 In this example, we will reproduce the file modification history of
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
196 figure~\ref{fig:tour-merge:conflict} above. Let's begin by creating a
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
197 repository with a base version of our document.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
198 \interaction{tour-merge-conflict.wife}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
199 We'll clone the repository and make a change to the file.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
200 \interaction{tour-merge-conflict.cousin}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
201 And another clone, to simulate someone else making a change to the
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
202 file. (This hints at the idea that it's not all that unusual to merge
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
203 with yourself when you isolate tasks in separate repositories, and
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
204 indeed to find and resolve conflicts while doing so.)
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
205 \interaction{tour-merge-conflict.son}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
206 Having created two different versions of the file, we'll set up an
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
207 environment suitable for running our merge.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
208 \interaction{tour-merge-conflict.pull}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
209
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
210 In this example, I won't use Mercurial's normal \command{hgmerge}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
211 program to do the merge, because it would drop my nice automated
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
212 example-running tool into a graphical user interface. Instead, I'll
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
213 set \envar{HGMERGE} to tell Mercurial to use the non-interactive
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
214 \command{merge} command. This is bundled with many Unix-like systems.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
215 If you're following this example on your computer, don't bother
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
216 setting \envar{HGMERGE}.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
217 \interaction{tour-merge-conflict.merge}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
218 Because \command{merge} can't resolve the conflicting changes, it
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
219 leaves \emph{merge markers} inside the file that has conflicts,
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
220 indicating which lines have conflicts, and whether they came from our
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
221 version of the file or theirs.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
222
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
223 Mercurial can tell from the way \command{merge} exits that it wasn't
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
224 able to merge successfully, so it tells us what commands we'll need to
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
225 run if we want to redo the merging operation. This could be useful
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
226 if, for example, we were running a graphical merge tool and quit
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
227 because we were confused or realised we had made a mistake.
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
228
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
229 If automatic or manual merges fail, there's nothing to prevent us from
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
230 ``fixing up'' the affected files ourselves, and committing the results
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
231 of our merge:
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
232 \interaction{tour-merge-conflict.commit}
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
233
224
34943a3d50d6 Start writing up extensions. Begin with inotify.
Bryan O'Sullivan <bos@serpentine.com>
parents: 103
diff changeset
234 \section{Simplifying the pull-merge-commit sequence}
34943a3d50d6 Start writing up extensions. Begin with inotify.
Bryan O'Sullivan <bos@serpentine.com>
parents: 103
diff changeset
235 \label{sec:tour-merge:fetch}
102
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
236
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
237 The process of merging changes as outlined above is straightforward,
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
238 but requires running three commands in sequence.
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
239 \begin{codesample2}
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
240 hg pull
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
241 hg merge
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
242 hg commit -m 'Merged remote changes'
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
243 \end{codesample2}
103
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
244 In the case of the final commit, you also need to enter a commit
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
245 message, which is almost always going to be a piece of uninteresting
5b80c922ebdd More merge content.
Bryan O'Sullivan <bos@serpentine.com>
parents: 102
diff changeset
246 ``boilerplate'' text.
102
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
247
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
248 It would be nice to reduce the number of steps needed, if this were
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
249 possible. Indeed, Mercurial is distributed with an extension called
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
250 \hgext{fetch} that does just this.
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
251
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
252 Mercurial provides a flexible extension mechanism that lets people
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
253 extend its functionality, while keeping the core of Mercurial small
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
254 and easy to deal with. Some extensions add new commands that you can
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
255 use from the command line, while others work ``behind the scenes,''
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
256 for example adding capabilities to the server.
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
257
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
258 The \hgext{fetch} extension adds a new command called, not
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
259 surprisingly, \hgcmd{fetch}. This extension acts as a combination of
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
260 \hgcmd{pull}, \hgcmd{update} and \hgcmd{merge}. It begins by pulling
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
261 changes from another repository into the current repository. If it
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
262 finds that the changes added a new head to the repository, it begins a
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
263 merge, then commits the result of the merge with an
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
264 automatically-generated commit message. If no new heads were added,
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
265 it updates the working directory to the new tip changeset.
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
266
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
267 Enabling the \hgext{fetch} extension is easy. Edit your
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
268 \sfilename{.hgrc}, and either go to the \rcsection{extensions} section
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
269 or create an \rcsection{extensions} section. Then add a line that
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
270 simply reads ``\Verb+fetch +''.
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
271 \begin{codesample2}
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
272 [extensions]
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
273 fetch =
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
274 \end{codesample2}
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
275 (Normally, on the right-hand side of the ``\texttt{=}'' would appear
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
276 the location of the extension, but since the \hgext{fetch} extension
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
277 is in the standard distribution, Mercurial knows where to search for
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
278 it.)
ff9dc8bc2a8b More. Merge. Stuff.
Bryan O'Sullivan <bos@serpentine.com>
parents: 101
diff changeset
279
84
43b9793b4e38 Begin tour chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
280 %%% Local Variables:
43b9793b4e38 Begin tour chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
281 %%% mode: latex
43b9793b4e38 Begin tour chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
282 %%% TeX-master: "00book"
43b9793b4e38 Begin tour chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
283 %%% End: