comparison en/tour-merge.tex @ 102:ff9dc8bc2a8b

More. Merge. Stuff.
author Bryan O'Sullivan <bos@serpentine.com>
date Wed, 18 Oct 2006 15:47:04 -0700
parents 321732566ac1
children 5b80c922ebdd
comparison
equal deleted inserted replaced
101:321732566ac1 102:ff9dc8bc2a8b
42 We already know that pulling changes from our \dirname{my-hello} 42 We already know that pulling changes from our \dirname{my-hello}
43 repository will have no effect on the working directory. 43 repository will have no effect on the working directory.
44 \interaction{tour.merge.pull} 44 \interaction{tour.merge.pull}
45 However, the \hgcmd{pull} command says something about ``heads''. 45 However, the \hgcmd{pull} command says something about ``heads''.
46 46
47 \subsection{Head changesets}
48
47 A head is a change that has no descendants, or children, as they're 49 A head is a change that has no descendants, or children, as they're
48 also known. The tip revision is thus a head, because the newest 50 also known. The tip revision is thus a head, because the newest
49 revision in a repository doesn't have any children, but a repository 51 revision in a repository doesn't have any children, but a repository
50 can contain more than one head. 52 can contain more than one head.
51 53
66 \emph{revision number} has changed. (This, incidentally, is a fine 68 \emph{revision number} has changed. (This, incidentally, is a fine
67 example of why it's not safe to use revision numbers when discussing 69 example of why it's not safe to use revision numbers when discussing
68 changesets.) We can view the heads in a repository using the 70 changesets.) We can view the heads in a repository using the
69 \hgcmd{heads} command. 71 \hgcmd{heads} command.
70 \interaction{tour.merge.heads} 72 \interaction{tour.merge.heads}
73
74 \subsection{Performing the merge}
75
71 What happens if we try to use the normal \hgcmd{update} command to 76 What happens if we try to use the normal \hgcmd{update} command to
72 update to the new tip? 77 update to the new tip?
73 \interaction{tour.merge.update} 78 \interaction{tour.merge.update}
74 Mercurial is telling us that the \hgcmd{update} command won't do a 79 Mercurial is telling us that the \hgcmd{update} command won't do a
75 merge; it won't update the working directory when it thinks we might 80 merge; it won't update the working directory when it thinks we might
87 92
88 This updates the working directory so that it contains changes from 93 This updates the working directory so that it contains changes from
89 \emph{both} heads, which is reflected in both the output of 94 \emph{both} heads, which is reflected in both the output of
90 \hgcmd{parents} and the contents of \filename{hello.c}. 95 \hgcmd{parents} and the contents of \filename{hello.c}.
91 \interaction{tour.merge.parents} 96 \interaction{tour.merge.parents}
97
98 \subsection{Committing the results of the merge}
99
92 Whenever we've done a merge, \hgcmd{parents} will display two parents 100 Whenever we've done a merge, \hgcmd{parents} will display two parents
93 until we \hgcmd{commit} the results of the merge. 101 until we \hgcmd{commit} the results of the merge.
94 \interaction{tour.merge.commit} 102 \interaction{tour.merge.commit}
95 We now have a new tip revision; notice that it has \emph{both} of 103 We now have a new tip revision; notice that it has \emph{both} of
96 our former heads as its parents. These are the same revisions that 104 our former heads as its parents. These are the same revisions that
100 what happens to the working directory during the merge, and how this 108 what happens to the working directory during the merge, and how this
101 affects the repository when the commit happens. During the merge, the 109 affects the repository when the commit happens. During the merge, the
102 working directory has two parent changesets, and these become the 110 working directory has two parent changesets, and these become the
103 parents of the new changeset. 111 parents of the new changeset.
104 112
113 \section{Merging conflicting changes}
114
115 Most merges are simple affairs, but sometimes you'll find yourself
116 merging a change that you made with another, where both modify the
117 same portions of the same files. Unless both modifications are
118 identical, this results in a \emph{conflict}, where you have to decide
119 how to reconcile the different changes into something coherent.
120
121 \section{Using an extension to simplify merging}
122
123 The process of merging changes as outlined above is straightforward,
124 but requires running three commands in sequence.
125 \begin{codesample2}
126 hg pull
127 hg merge
128 hg commit -m 'Merged remote changes'
129 \end{codesample2}
130 In the case of the final commit, you also need to come up with a
131 commit message, which is almost always going to be a piece of
132 uninteresting ``boilerplate'' text.
133
134 It would be nice to reduce the number of steps needed, if this were
135 possible. Indeed, Mercurial is distributed with an extension called
136 \hgext{fetch} that does just this.
137
138 Mercurial provides a flexible extension mechanism that lets people
139 extend its functionality, while keeping the core of Mercurial small
140 and easy to deal with. Some extensions add new commands that you can
141 use from the command line, while others work ``behind the scenes,''
142 for example adding capabilities to the server.
143
144 The \hgext{fetch} extension adds a new command called, not
145 surprisingly, \hgcmd{fetch}. This extension acts as a combination of
146 \hgcmd{pull}, \hgcmd{update} and \hgcmd{merge}. It begins by pulling
147 changes from another repository into the current repository. If it
148 finds that the changes added a new head to the repository, it begins a
149 merge, then commits the result of the merge with an
150 automatically-generated commit message. If no new heads were added,
151 it updates the working directory to the new tip changeset.
152
153 Enabling the \hgext{fetch} extension is easy. Edit your
154 \sfilename{.hgrc}, and either go to the \rcsection{extensions} section
155 or create an \rcsection{extensions} section. Then add a line that
156 simply reads ``\Verb+fetch +''.
157 \begin{codesample2}
158 [extensions]
159 fetch =
160 \end{codesample2}
161 (Normally, on the right-hand side of the ``\texttt{=}'' would appear
162 the location of the extension, but since the \hgext{fetch} extension
163 is in the standard distribution, Mercurial knows where to search for
164 it.)
165
105 %%% Local Variables: 166 %%% Local Variables:
106 %%% mode: latex 167 %%% mode: latex
107 %%% TeX-master: "00book" 168 %%% TeX-master: "00book"
108 %%% End: 169 %%% End: