annotate es/tour-merge.tex @ 480:7ca1186c422f

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