Mercurial > hgbook
annotate en/tour-merge.tex @ 100:272146fab009
Add yet another illustration of the merge process.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Wed, 18 Oct 2006 12:06:56 -0700 |
parents | 06383f9e46e4 |
children | 321732566ac1 |
rev | line source |
---|---|
95
47ea206351d5
Split tour into two sections.
Bryan O'Sullivan <bos@serpentine.com>
parents:
94
diff
changeset
|
1 \chapter{A tour of Mercurial: merging work} |
47ea206351d5
Split tour into two sections.
Bryan O'Sullivan <bos@serpentine.com>
parents:
94
diff
changeset
|
2 \label{chap:tour-merge} |
94 | 3 |
4 We've now covered cloning a repository, making changes in a | |
5 repository, and pulling or pushing changes from one repository into | |
6 another. Our next step is \emph{merging} changes from separate | |
7 repositories. | |
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 | 11 Merging is a fundamental part of working with a distributed revision |
12 control tool. | |
13 \begin{itemize} | |
14 \item Alice and Bob each have a personal copy of a repository for a | |
15 project they're collaborating on. Alice fixes a bug in her | |
16 repository; Bob adds a new feature in his. They want the shared | |
17 repository to contain both the bug fix and the new feature. | |
18 \item I frequently work on several different tasks for a single | |
19 project at once, each safely isolated in its own repository. | |
20 Working this way means that I often need to merge one piece of my | |
21 own work with another. | |
22 \end{itemize} | |
23 | |
24 Because merging is such a common thing to need to do, Mercurial makes | |
25 it easy. Let's walk through the process. We'll begin by cloning yet | |
26 another repository (see how often they spring up?) and making a change | |
27 in it. | |
28 \interaction{tour.merge.clone} | |
29 We should now have two copies of \filename{hello.c} with different | |
99 | 30 contents. The histories of the two repositories have also diverged, |
31 as illustrated in figure~\ref{fig:tour-merge:sep-repos}. | |
94 | 32 \interaction{tour.merge.cat} |
33 | |
99 | 34 \begin{figure}[ht] |
35 \centering | |
36 \grafix{tour-merge-sep-repos} | |
37 \caption{Divergent recent histories of the \dirname{my-hello} and | |
38 \dirname{my-new-hello} repositories} | |
39 \label{fig:tour-merge:sep-repos} | |
40 \end{figure} | |
41 | |
94 | 42 We already know that pulling changes from our \dirname{my-hello} |
43 repository will have no effect on the working directory. | |
44 \interaction{tour.merge.pull} | |
45 However, the \hgcmd{pull} command says something about ``heads''. | |
46 | |
99 | 47 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 | |
49 revision in a repository doesn't have any children, but a repository | |
50 can contain more than one head. | |
51 | |
52 \begin{figure}[ht] | |
53 \centering | |
54 \grafix{tour-merge-pull} | |
55 \caption{Repository contents after pulling from \dirname{my-hello} into | |
56 \dirname{my-new-hello}} | |
57 \label{fig:tour-merge:pull} | |
58 \end{figure} | |
59 | |
60 In figure~\ref{fig:tour-merge:pull}, you can see the effect of the | |
61 pull from \dirname{my-hello} into \dirname{my-new-hello}. The history | |
62 that was already present in \dirname{my-new-hello} is untouched, but a | |
63 new revision has been added. By referring to | |
64 figure~\ref{fig:tour-merge:sep-repos}, we can see that the | |
65 \emph{changeset ID} remains the same in the new repository, but the | |
66 \emph{revision number} has changed. (This, incidentally, is a fine | |
67 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 | |
69 \hgcmd{heads} command. | |
94 | 70 \interaction{tour.merge.heads} |
71 What happens if we try to use the normal \hgcmd{update} command to | |
72 update to the new tip? | |
73 \interaction{tour.merge.update} | |
74 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
|
75 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
|
76 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
|
77 use the \hgcmd{merge} command to merge the two heads. |
94 | 78 \interaction{tour.merge.merge} |
100
272146fab009
Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents:
99
diff
changeset
|
79 |
272146fab009
Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents:
99
diff
changeset
|
80 \begin{figure}[ht] |
272146fab009
Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents:
99
diff
changeset
|
81 \centering |
272146fab009
Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents:
99
diff
changeset
|
82 \grafix{tour-merge-merge} |
272146fab009
Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents:
99
diff
changeset
|
83 \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
|
84 following commit} |
272146fab009
Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents:
99
diff
changeset
|
85 \label{fig:tour-merge:merge} |
272146fab009
Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents:
99
diff
changeset
|
86 \end{figure} |
272146fab009
Add yet another illustration of the merge process.
Bryan O'Sullivan <bos@serpentine.com>
parents:
99
diff
changeset
|
87 |
94 | 88 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
|
89 \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
|
90 \hgcmd{parents} and the contents of \filename{hello.c}. |
94 | 91 \interaction{tour.merge.parents} |
92 Whenever we've done a merge, \hgcmd{parents} will display two parents | |
93 until we \hgcmd{commit} the results of the merge. | |
94 \interaction{tour.merge.commit} | |
95 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 | |
97 were previously displayed by \hgcmd{parents}. | |
98 \interaction{tour.merge.tip} | |
99 | |
84 | 100 %%% Local Variables: |
101 %%% mode: latex | |
102 %%% TeX-master: "00book" | |
103 %%% End: |