Mercurial > hgbook
view ja/tour-merge.tex @ 800:1a30d2627512
Propagate 2ff0a43f1152
Update ch03
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Thu, 18 Jun 2009 20:04:44 +0900 |
parents | 7107b79427a3 |
children | 8a3041e6f3cb |
line wrap: on
line source
%\chapter{A tour of Mercurial: merging work} \chapter{Mercurial$B%D%"!<(B: $B%^!<%8(B} \label{chap:tour-merge} %We've now covered cloning a repository, making changes in a %repository, and pulling or pushing changes from one repository into %another. Our next step is \emph{merging} changes from separate %repositories. $B2f!9$O4{$K%j%]%8%H%j$N%/%m!<%s!$%j%]%8%H%j$KBP$9$kJQ99!$(B1$B$D$N%j%]%8%H%j$+(B $B$i$N(Bpull$B$HJL$N(B1$B$D$N%j%]%8%H%j$KBP$9$k(Bpush$B$r9T$C$?!%<!$N%9%F%C%W$OJL$N%j%](B $B%8%H%j$+$iJQ99$r(B\emph{$B%^!<%8(B}$B$9$k$3$H$G$"$k!%(B %\section{Merging streams of work} \section{$BJ#?t$N:n6H7k2L$r%^!<%8$9$k(B} %Merging is a fundamental part of working with a distributed revision %control tool. $B%^!<%8$OJ,;6%j%S%8%g%s%3%s%H%m!<%k%D!<%k$G$N:n6H$K$*$$$FIT2D7g$NItJ,$G$"(B $B$k!%(B \begin{itemize} %\item Alice and Bob each have a personal copy of a repository for a % project they're collaborating on. Alice fixes a bug in her % repository; Bob adds a new feature in his. They want the shared % repository to contain both the bug fix and the new feature. \item $B%"%j%9$H%\%V$O6&F1:n6H$7$F$$$k%W%m%8%'%/%H$N%j%]%8%H%j%3%T!<$r3F!9(B $B;}$C$F$$$k!%%"%j%9$O<+J,$N%j%]%8%H%j$G%P%0$r=$@5$7!$%\%V$OH`$N%j%]%8%H%j(B $B$G?75!G=$rDI2C$7$?!%H`$i$O%P%0=$@5$H?75!G=$NN>J}$r;}$D%j%]%8%H%j$r6&M-$7(B $B$?$$$H9M$($F$$$k!%(B %\item I frequently work on several different tasks for a single % project at once, each safely isolated in its own repository. % Working this way means that I often need to merge one piece of my % own work with another. \item $B;d$O0l$D$N%W%m%8%'%/%H$NJL!9$N%?%9%/$KBP$7$FF1;~$K:n6H$r9T$&$3$H$r(B $B$h$/9T$C$F$$$k!%$3$N$h$&$J:n6H%9%?%$%k$G$O!$<+J,$N:n6H$N0l$D$+$iJL(B $B$N:n6H$N0l$D$X7k2L$r%^!<%8$7$?$$$H;W$&$3$H$,$7$P$7$P$"$k!%(B \end{itemize} %Because merging is such a common thing to need to do, Mercurial makes %it easy. Let's walk through the process. We'll begin by cloning yet %another repository (see how often they spring up?) and making a change %in it. $B>e$G=R$Y$?$h$&$K%^!<%8$r9T$$$?$$>u67$O$H$F$bB?$$$?$a!$(B Mercurial$B$G$O%^!<(B $B%8$r4JC1$K9T$($k$h$&$K$J$C$F$$$k!%$^$:JL$N%j%]%8%H%j$r%/%m!<%s$7!$JQ99$r(B $B2C$($k$H$3$m$+$i;O$a$h$&!%(B \interaction{tour.merge.clone} %We should now have two copies of \filename{hello.c} with different %contents. The histories of the two repositories have also diverged, %as illustrated in figure~\ref{fig:tour-merge:sep-repos}. $B:#!$FbMF$N0[$J$C$?(B2$B$D$N(B\filename{hello.c}$B$,$"$k!%(B 2$B$D$N%j%]%8%H%j$NMzNr$O(B $B?^(B~\ref{fig:tour-merge:sep-repos}$B$K<($9$h$&$KJ,$+$l$F$$$k!%(B \interaction{tour.merge.cat} \begin{figure}[ht] \centering \grafix{tour-merge-sep-repos} % \caption{Divergent recent histories of the \dirname{my-hello} and % \dirname{my-new-hello} repositories} \caption{\dirname{my-hello}$B%j%]%8%H%j$H(B\dirname{my-new-hello}$B%j%]%8%H(B $B%j$NMzNr$N:90[(B} \label{fig:tour-merge:sep-repos} \end{figure} %We already know that pulling changes from our \dirname{my-hello} %repository will have no effect on the working directory. $B4{$K(B\dirname{my-hello}$B%j%]%8%H%j$+$i$N(Bpull$B$O%o!<%-%s%0%G%#%l%/%H%j$K2?$N(B $B1F6A$bM?$($J$$$3$H$r3X$s$@!%(B \interaction{tour.merge.pull} %However, the \hgcmd{pull} command says something about ``heads''. $B$7$+$7(B\hgcmd{pull}$B%3%^%s%I$O(B``heads''$B$K$D$$$F%a%C%;!<%8$rI=<($9$k!%(B %\subsection{Head changesets} \subsection{Head$B%A%'%s%8%;%C%H(B} %A head is a change that has no descendants, or children, as they're %also known. The tip revision is thus a head, because the newest %revision in a repository doesn't have any children, but a repository %can contain more than one head. head$B$O;RB9$d;R$r;}$?$J$$JQ99$G$"$k!%%j%]%8%H%j$N:G?7$N%j%S%8%g%s$O;R$r;}(B $B$?$J$$$?$a!$(Btip$B%j%S%8%g%s$O$9$J$o$A(Bhead$B$G$"$k!%0lJ}$G%j%]%8%H%j$OJ#?t$N(B head$B$r;}$AF@$k!%(B \begin{figure}[ht] \centering \grafix{tour-merge-pull} % \caption{Repository contents after pulling from \dirname{my-hello} into % \dirname{my-new-hello}} \caption{\dirname{my-hello}$B$+$i(B\dirname{my-new-hello}$B$X(Bpull$B$7$?$"$H$N(B $B%j%]%8%H%j$NFbMF(B} \label{fig:tour-merge:pull} \end{figure} %In figure~\ref{fig:tour-merge:pull}, you can see the effect of the %pull from \dirname{my-hello} into \dirname{my-new-hello}. The history %that was already present in \dirname{my-new-hello} is untouched, but a %new revision has been added. By referring to %figure~\ref{fig:tour-merge:sep-repos}, we can see that the %\emph{changeset ID} remains the same in the new repository, but the %\emph{revision number} has changed. (This, incidentally, is a fine %example of why it's not safe to use revision numbers when discussing %changesets.) We can view the heads in a repository using the %\hgcmd{heads} command. %\interaction{tour.merge.heads} $B?^(B~\ref{fig:tour-merge:pull}$B$K(B\dirname{my-hello}$B$+$i(B \dirname{my-new-hello}$B$X(Bpull$B$r9T$C$?8z2L$r<($9!%(B \dirname{my-new-hello}$B$K(B $B4{$KB8:_$7$?MzNr$OJQ99$5$l$:!$?7$?$K%j%S%8%g%s$,DI2C$5$l$k!%(B figure~\ref{fig:tour-merge:sep-repos}$B$r8+$k$H!$?7$7$$%j%]%8%H%j$K$b(B \emph{changeset ID}$B$,;D$C$F$$$k$3$H!$(B\emph{$B%j%S%8%g%sHV9f(B}$B$,JQ99$5$l$F$$(B $B$k$3$H$,J,$+$k!%(B $B!J$3$l$OF1;~$K%A%'%s%8%;%C%H$K$D$$$FO@$8$k:]$K%j%S%8%g%s(B $BHV9f$rMQ$$$k$N$,0BA4$G$J$$$3$H$NNc$K$J$C$F$$$k!%!K%j%]%8%H%jFb$K$"$k(Bhead $B$O(B\hgcmd{heads}$B$K$h$C$F8+$k$3$H$,$G$-$k!%(B \interaction{tour.merge.heads} %\subsection{Performing the merge} \subsection{$B%^!<%8$r<B9T$9$k(B} %What happens if we try to use the normal \hgcmd{update} command to %update to the new tip? %\interaction{tour.merge.update} $B?7$7$$(Btip$B$X99?7$9$k$?$a$K(B\hgcmd{update}$B$r;H$C$?>l9g2?$,5/$-$k$+!)(B \interaction{tour.merge.update} %Mercurial is telling us that the \hgcmd{update} command won't do a %merge; it won't update the working directory when it thinks we might %want to do a merge, unless we force it to do so. Instead, we %use the \hgcmd{merge} command to merge the two heads. %\interaction{tour.merge.merge} Mercurial$B$O(B\hgcmd{update}$B%3%^%s%I$,%^!<%8$r9T$o$J$$$H%a%C%;!<%8$rI=<($9(B $B$k!%(B \hgcmd{update}$B%3%^%s%I$O!$%^!<%8$,I,MW$H9M$($i$l$k>l9g$O!$%f!<%6$,(B $B!J%*%W%7%g%s$K$h$C$F!K6/@)$7$J$$8B$j%o!<%-%s%0%G%#%l%/%H%j$r99?7$7$J$$!%(B $B0lJ}!$(B\hgcmd{merge}$B%3%^%s%I$O(B2$B$D$N%X%C%I$N%^!<%8$r9T$&!%(B \interaction{tour.merge.merge} %This updates the working directory so that it contains changes from %\emph{both} heads, which is reflected in both the output of %\hgcmd{parents} and the contents of \filename{hello.c}. %\interaction{tour.merge.parents} $B$3$NA`:n$K$h$C$F(B\hgcmd{parents}$B$H(B\filename{hello.c}$B$N=PNO$NAPJ}$rH?1G$9$k(B \emph{$BAPJ}$N(B}head$B$+$i$NJQ99$r4^$`$h$&$K%o!<%-%s%0%G%#%l%/%H%j$,99?7$5$l$k!%(B %\subsection{Committing the results of the merge} \subsection{$B%^!<%87k2L$r%3%_%C%H$9$k(B} %Whenever we've done a merge, \hgcmd{parents} will display two parents %until we \hgcmd{commit} the results of the merge. %\interaction{tour.merge.commit} $B%^!<%8$r9T$&$H!$%^!<%8$N7k2L$r(B\hgcmd{commit}$B$9$k$^$G!$(B\hgcmd{parents}$B$O(B2 $B$D$N%Z%"%l%s%H$rI=<($9$k!%(B \interaction{tour.merge.commit} %We now have a new tip revision; notice that it has \emph{both} of %our former heads as its parents. These are the same revisions that %were previously displayed by \hgcmd{parents}. %\interaction{tour.merge.tip} $B?7$7$$(Btip$B%j%S%8%g%s$O0JA0$N%X%C%I(B\emph{$BN>J}(B}$B$r?F$H$7$F;}$D!%$3$l$i$O(B \hgcmd{parents}$B%3%^%s%I$GI=<($7$?$N$HF1$8%j%S%8%g%s$G$"$k!%(B \interaction{tour.merge.tip} %In figure~\ref{fig:tour-merge:merge}, you can see a representation of %what happens to the working directory during the merge, and how this %affects the repository when the commit happens. During the merge, the %working directory has two parent changesets, and these become the %parents of the new changeset. $B?^(B~\ref{fig:tour-merge:merge}$B$G!$%^!<%8$N4V$K%o!<%-%s%0%G%#%l%/%H%j$K2?$,(B $B5/$-!$%3%_%C%H$7$?;~$K%j%]%8%H%j$K$I$&1F6A$9$k$N$+$r8+$k$3$H$,$G$-$k!%(B $B%^!<%8$N4V!$%o!<%-%s%0%G%#%l%/%H%j$O(B2$B$D$N?F%A%'%s%8%;%C%H$r;}$A!$$3$l$i$O(B $B?7$7$$%A%'%s%8%;%C%H$NN>?F$H$J$k!%(B \begin{figure}[ht] \centering \grafix{tour-merge-merge} % \caption{Working directory and repository during merge, and % following commit} \caption{$B%^!<%8Cf$N%o!<%-%s%0%G%#%l%/%H%j$H%j%]%8%H%j$*$h$S8eB3$N%3%_%C(B $B%H(B} \label{fig:tour-merge:merge} \end{figure} %We sometimes talk about a merge having \emph{sides}: the left side is %the first parent in the output of \hgcmd{parents}, and the right side is %the second. If the working directory was at e.g. revision 5 before we %began a merge, that revision will become the left side of the merge. $B%^!<%8$K$h$j(B\emph{$B%5%$%I(B}$B$,$G$-$k$3$H$,$"$k!%:8$N%5%$%I$O(B\hgcmd{parents} $B$N=PNO$N:G=i$N?F$G!$1&$N%5%$%I$,(B2$BHVL\$N?F$G$"$k!%Nc$($P!$%^!<%8A0$K%o!<%-(B $B%s%0%G%#%l%/%H%j$,%j%S%8%g%s(B5$B$G$"$C$?$H$9$k$H!$%^!<%8$N:8$N%5%$%I$,$3$N(B $B%j%S%8%g%s$K$J$k!%(B %\section{Merging conflicting changes} \section{$B%3%s%U%j%/%H$N$"$kJQ99$r%^!<%8$9$k(B} %Most merges are simple affairs, but sometimes you'll find yourself %merging changes where each side modifies the same portions of the same %files. Unless both modifications are identical, this results in a %\emph{conflict}, where you have to decide how to reconcile the %different changes into something coherent. $BBgH>$N%^!<%8$O%7%s%W%k$J$b$N$@$,!$F1$8%U%!%$%k$NF1$82U=j$rJQ99$9$k%A%'%s(B $B%8%;%C%H$r%^!<%8$7$J$1$l$P$J$i$J$$$3$H$b$"$k!%3F!9$NJQ99$,F1$8FbMF$G$J$$(B $B8B$j!$7k2L$O(B\emph{conflict}$B$H$J$k$?$a!$JQ99$r@09g$5$;$k$h$&$K=$@5$9$kI,MW(B $B$,$"$k!%(B \begin{figure}[ht] \centering \grafix{tour-merge-conflict} % \caption{Conflicting changes to a document} \caption{$B%3%s%U%j%/%H$7$?%A%'%s%8%;%C%H(B} \label{fig:tour-merge:conflict} \end{figure} %Figure~\ref{fig:tour-merge:conflict} illustrates an instance of two %conflicting changes to a document. We started with a single version %of the file; then we made some changes; while someone else made %different changes to the same text. Our task in resolving the %conflicting changes is to decide what the file should look like. 1$B$D$N%I%-%e%a%s%H$KBP$7$F(B2$B$D$N%A%'%s%8%;%C%H$,%3%s%U%j%/%H$7$?MM;R$r(B $B?^(B~\ref{fig:tour-merge:conflict}$B$K<($9!%(B $B$3$3$G$O!$$"$k(B1$B$D$N%P!<%8%g%s$N%U%!%$%k$K$$$/$D$+$NJQ99$r2C$(!$F1;~$KJL$N(B $B?M$,JL$NJQ99$rF1$8%F%-%9%H$KBP$7$F2C$($F$$$k!%%A%'%s%8%;%C%H$N%3%s%U%j%/(B $B%H$r2r7h$9$k$?$a!$%U%!%$%k$,$I$&$"$k$Y$-$+$rL@$i$+$K$7$h$&!%(B %Mercurial doesn't have a built-in facility for handling conflicts. %Instead, it runs an external program, usually one that displays some %kind of graphical conflict resolution interface. By default, Mercurial %tries to find one of several different merging tools that are likely to %be installed on your system. It first tries a few fully automatic %merging tools; if these don't succeed (because the resolution process %requires human guidance) or aren't present, it tries a few different %graphical merging tools. Mercurial$B$OFbB"$N%3%s%U%j%/%H2r7h5!9=$r;}$?$J$$!%$=$NBe$o$j!$2?$i$+$N%0%i(B $B%U%#%+%k$J%3%s%U%j%/%H2r7h%$%s%?%U%'!<%9$rI=<($9$k30It%3%^%s%I$r5/F0$9(B $B$k!%%G%U%)%k%H$G(BMercurial$B$O%7%9%F%`$K%$%s%9%H!<%k$5$l$F$$$k2DG=@-$N9b$$$$(B $B$/$D$+$N%^!<%8%D!<%k$rA\$9!%(BMercurial$B$O:G=i$K(B2,3$B$NA4<+F0$N%^!<%8%D!<%k$r(B $B;n$9!%$3$l$G$&$^$/$$$+$J$$>l9g!J2r7h%W%m%;%9$K?M$N%,%$%I$,I,MW$J>l9g!K$d(B $B%D!<%k$,B8:_$7$J$$>l9g!$%9%/%j%W%H$OJL$N(B2,3$B$N%0%i%U%#%+%k%^!<%8%D!<%k$r;n(B $B$9!%(B %It's also possible to get Mercurial to run another program or script %instead of \command{hgmerge}, by setting the \envar{HGMERGE} %environment variable to the name of your preferred program. $B4D6-JQ?t(B\envar{HGMERGE}$B$K9%$_$N%W%m%0%i%`L>$r$r@_Dj$9$k$3$H$G!$(BMercurial $B$,(B\command{hgmerge}$B0J30$N%9%/%j%W%H$r5/F0$9$k$h$&$K$9$k$3$H$b2DG=$G$"$k!%(B %\subsection{Using a graphical merge tool} \subsection{$B%0%i%U%#%+%k%^!<%8%D!<%k$N;HMQ(B} %My preferred graphical merge tool is \command{kdiff3}, which I'll use %to describe the features that are common to graphical file merging %tools. You can see a screenshot of \command{kdiff3} in action in %figure~\ref{fig:tour-merge:kdiff3}. The kind of merge it is %performing is called a \emph{three-way merge}, because there are three %different versions of the file of interest to us. The tool thus %splits the upper portion of the window into three panes: $BI.<T$N9%$_$N%0%i%U%#%+%k%^!<%8%D!<%k$O(B\command{kdiff3}$B$J$N$G!$$3$l$r;H$C(B $B$F%0%i%U%#%+%k%U%!%$%k%^!<%8%D!<%k$N5!G=$r@bL@$9$k!%(B $B?^(B~\ref{fig:tour-merge:kdiff3}$B$K(B\command{kdiff3}$B$N<B:]$NF0:n$N%9%/%j!<%s(B $B%7%g%C%H$r<($9!%:#CmL\$7$F$$$k%U%!%$%k$K$O(B3$B$D$N0[$J$C$?%P!<%8%g%s$,$"$k$?(B $B$a!$$3$3$G<B9T$5$l$F$$$k$N$O(B\emph{3way$B%^!<%8(B}$B$G$"$k!%%D!<%k$O%&%#%s%I%&$N(B $B>eIt$r(B3$B$D$N%Z!<%s$KJ,3d$7$F$$$k!%(B \begin{itemize} %\item At the left is the \emph{base} version of the file, i.e.~the % most recent version from which the two versions we're trying to % merge are descended. \item $B:8$K$"$k$N$O%U%!%$%k$N(B\emph{$B%Y!<%9(B}$B%P!<%8%g%s$G$"$k!%$3$l$O$3$l$+(B $B$i%^!<%8$7$h$&$H$9$k(B2$B$D$N%P!<%8%g%s$N?F$H$J$k:G$b:G6a$N%P!<%8%g%s(B $B$G$"$k!%(B %\item In the middle is ``our'' version of the file, with the contents % that we modified. \item $BCf1{$K$"$k$N$O2f!9$,JQ99$r2C$($?%P!<%8%g%s$G$"$k!%(B %\item On the right is ``their'' version of the file, the one that % from the changeset that we're trying to merge with. \item $B1&$K$"$k$N$OB>$N?M$,JQ99$r2C$($?%P!<%8%g%s$G!$$3$l$+$i%^!<%8$7$h(B $B$&$H$9$k$b$N$G$"$k!%(B \end{itemize} %In the pane below these is the current \emph{result} of the merge. %Our task is to replace all of the red text, which indicates unresolved %conflicts, with some sensible merger of the ``ours'' and ``theirs'' %versions of the file. $B$3$N2<$N%Z!<%s$K$O%^!<%8$N(B\emph{$B7k2L(B}$B$,$"$k!%@V;z$N9T$O%3%s%U%j%/%H$r<($7(B $B$F$*$j!$2f!9$N%P!<%8%g%s$HB>$N?M$N%P!<%8%g%s$rCm0U?<$/%^!<%8$7$?7k2L$rMQ(B $B$$$F$3$l$i$r$9$Y$FCV$-49$($k!%(B %All four of these panes are \emph{locked together}; if we scroll %vertically or horizontally in any of them, the others are updated to %display the corresponding sections of their respective files. 4$B$D$N%Z!<%s$9$Y$F$O(B\emph{$BF14|(B}$B$7$F$*$j!"$I$l$+$r?bD>$^$?$O?eJ?$K%9%/%m!<(B $B%k$9$k$H!"B>$N(B3$B$D$bBP1~$9$k2U=j$rI=<($9$k$h$&$K99?7$5$l$k!#(B \begin{figure}[ht] \centering \grafix{kdiff3} % \caption{Using \command{kdiff3} to merge versions of a file} \caption{$B%U%!%$%k$NJ#?t%j%S%8%g%s$r(B\command{kdiff3}$B$r;H$C$F%^!<%8$9$k(B} \label{fig:tour-merge:kdiff3} \end{figure} %For each conflicting portion of the file, we can choose to resolve %the conflict using some combination of text from the base version, %ours, or theirs. We can also manually edit the merged file at any %time, in case we need to make further modifications. $B%3%s%U%j%/%H$r2r7h$9$k$?$a$K!$%U%!%$%kCf$N%3%s%U%j%/%H$7$F$$$k$9$Y$F$NIt(B $BJ,$KBP$7$F%Y!<%9%P!<%8%g%s!$2f!9$N%P!<%8%g%s!$JL$N?M!9$N%P!<%8%g%s$N%F%-(B $B%9%H$rAH$_9g$o$;$FMQ$$$k!%$5$i$J$k=$@5$,I,MW$J>l9g$O!$%^!<%8$5$l$?%U%!%$(B $B%k$r<jF0$GJT=8$9$k$3$H$b$G$-$k!%(B %There are \emph{many} file merging tools available, too many to cover %here. They vary in which platforms they are available for, and in %their particular strengths and weaknesses. Most are tuned for merging %files containing plain text, while a few are aimed at specialised file %formats (generally XML). \emph{$B?t!9$N(B}$B%^!<%8%D!<%k$,MxMQ2DG=$G$"$j!$$=$l$i$r%+%P!<$9$k$3$H$O$G$-$J(B $B$$!%$=$l$i$O!$MxMQ2DG=$J%W%i%C%H%U%)!<%`$,0[$J$j!$$=$l$>$lD9=j$H<eE@$,0[(B $B$J$k!%$[$H$s$I$,%W%l!<%s%F%-%9%H$r%^!<%8$9$k$h$&$K:n$i$l$F$$$k$,!$FCJL$J(B $B%U%!%$%k%U%)!<%^%C%H!J(BXML$B!K$KFC2=$7$F$$$k$b$N$b$"$k!%(B %\subsection{A worked example} \subsection{$B<B9TNc(B} %In this example, we will reproduce the file modification history of %figure~\ref{fig:tour-merge:conflict} above. Let's begin by creating a %repository with a base version of our document. %\interaction{tour-merge-conflict.wife} %We'll clone the repository and make a change to the file. %\interaction{tour-merge-conflict.cousin} %And another clone, to simulate someone else making a change to the %file. (This hints at the idea that it's not all that unusual to merge %with yourself when you isolate tasks in separate repositories, and %indeed to find and resolve conflicts while doing so.) %\interaction{tour-merge-conflict.son} %Having created two different versions of the file, we'll set up an %environment suitable for running our merge. %\interaction{tour-merge-conflict.pull} $B$3$NNc$G$OA0=R$N?^(B~\ref{fig:tour-merge:conflict}$B$G$NJQ99MzNr$r:F8=$9$k!%(B $BJ8=q$N%Y!<%9%P!<%8%g%s$r4^$`%j%]%8%H%j$r:n@.$9$k$3$H$+$i;O$a$k!%(B \interaction{tour-merge-conflict.wife} $B%j%]%8%H%j$r%3%T!<$7!$%U%!%$%k$KJQ99$r9T$&!%(B \interaction{tour-merge-conflict.cousin} $BJL$N?M$,JQ99$r9T$&$N$r%7%_%e%l!<%H$9$k$?$a$K$b$&0l$D$N%/%m!<%s$r:n@.$9(B $B$k!%!JJL!9$N%j%]%8%H%j$K3VN%$7$F9T$C$?:n6H$N7k2L$r%^!<%8$7!$%3%s%U%j%/%H(B $B$r2r>C$9$k$3$H$O>/$7$bDA$7$$$3$H$G$O$J$$$H$$$&;v$,$o$+$k$@$m$&!%(B $B!K(B \interaction{tour-merge-conflict.son} $B%U%!%$%k$K(B2$B$D$NJL$N%P!<%8%g%s$r:n$j!$%^!<%8$r9T$&$N$KE*2<4D6-$r@_Dj$9$k!%(B \interaction{tour-merge-conflict.pull} %In this example, I'll set \envar{HGMERGE} to tell Mercurial to use the %non-interactive \command{merge} command. This is bundled with many %Unix-like systems. (If you're following this example on your computer, %don't bother setting \envar{HGMERGE}.) $B$3$NNc$G$O(B\envar{HGMERGE}$B$r@_Dj$7$F!$(BMercurial$B$KHsBPOCE*$J(B \command{merge}$B%3%^%s%I$r5/F0$5$;$k!%$3$l$OB?$/$N(BUnix$B7O%7%9%F%`$K%P%s%I%k(B $B$5$l$F$$$k%3%^%s%I$G$"$k!%!J$3$NNc$r<j85$N%^%7%s$G<B9T$9$k;~$K$O(B \envar{HGMERGE}$B$r@_Dj$9$kI,MW$O$J$$!%!K(B %Mercurial can tell from the way \command{merge} exits that it wasn't %able to merge successfully, so it tells us what commands we'll need to %run if we want to redo the merging operation. This could be useful %if, for example, we were running a graphical merge tool and quit %because we were confused or realised we had made a mistake. Mercurial$B$O(B\command{merge}$B%3%^%s%I$G@5$7$/%^!<%8$G$-$J$+$C$?>l9g!$$b$&0l(B $BEY%^!<%8$r9T$&$?$a$K$I$N$h$&$K$9$l$P$$$$$N$+$rI=<($9$k!%$3$l$O!$%0%i%U%#(B $B%+%k%^!<%8%D!<%k$N;HMQCf$K:.Mp$rMh$7$?$+4V0c$$$rHH$7$?$3$H$K5$IU$$$?$?$a(B $B$K=*N;$7$?>l9g$J$I$KM-8z$G$"$m$&!%(B %If automatic or manual merges fail, there's nothing to prevent us from %``fixing up'' the affected files ourselves, and committing the results %of our merge: %\interaction{tour-merge-conflict.commit} $B<+F0$^$?$O<jF0$K$h$k%^!<%8$,<:GT$7$?>l9g!$1F6A$r<u$1$k%U%!%$%k$r(B``$B=$@5(B'' $B$7$F%^!<%8$N7k2L$r%3%_%C%H$7$J$1$l$P$J$i$J$$!%(B \interaction{tour-merge-conflict.commit} %\section{Simplifying the pull-merge-commit sequence} \section{pull-merge-commit$B<j=g$r4JC1$K$9$k(B} \label{sec:tour-merge:fetch} %The process of merging changes as outlined above is straightforward, %but requires running three commands in sequence. $BA0@a$G35MW$r=R$Y$?%A%'%s%8%;%C%H$N%^!<%8%W%m%;%9$OC1=c$J$b$N$@$C$?$,!$(B3 $B$D$N%3%^%s%I$r=g$KMQ$$$kI,MW$,$"$C$?!%(B \begin{codesample2} hg pull -u hg merge hg commit -m 'Merged remote changes' \end{codesample2} %In the case of the final commit, you also need to enter a commit %message, which is almost always going to be a piece of uninteresting %``boilerplate'' text. $B:G8e$N%3%_%C%H$G$O!$$[$H$s$IB`6~$J%\%$%i!<%W%l!<%H%F%-%9%H$H8@$C$F$b$h$$(B $B%3%_%C%H%a%C%;!<%8$NF~NO$bI,MW$G$"$C$?!%(B %It would be nice to reduce the number of steps needed, if this were %possible. Indeed, Mercurial is distributed with an extension called %\hgext{fetch} that does just this. $B2DG=$G$"$l$PI,MW$J%9%F%C%W?t$r>/$J$/$9$k$3$H$,$G$-$k$H$h$$!%<B$O(B Mercurial$B$O(B\hgext{fetch}$B$H$$$&!$$^$5$K$3$N$3$H$r9T$&%(%/%9%F%s%7%g%s$rF1(B $B:-$7$F$$$k!%(B %Mercurial provides a flexible extension mechanism that lets people %extend its functionality, while keeping the core of Mercurial small %and easy to deal with. Some extensions add new commands that you can %use from the command line, while others work ``behind the scenes,'' %for example adding capabilities to the server. Mercurial$B$O%3%"$r>.$5$/!$07$$$d$9$/J]$C$?$^$^5!G=$r3HD%$G$-$k=@Fp$J%(%96e(B $B%F%s%7%g%s%a%+%K%:%`$rDs6!$7$F$$$k!%%3%^%s%I%i%$%s$+$iMxMQ$G$-$k?7$7$$%3(B $B%^%s%I$rDI2C$9$k$h$&$J%(%/%9%F%s%7%g%s$b$"$l$P!$L\$K8+$($J$$$H$3$m$GNc$((B $B$P%5!<%P$K5!G=$rDI2C$9$k$h$&$J$b$N$b$"$k!%(B %The \hgext{fetch} extension adds a new command called, not %surprisingly, \hgcmd{fetch}. This extension acts as a combination of %\hgopt{pull}{-u}, \hgcmd{merge} and \hgcmd{commit}. It begins by pulling %changes from another repository into the current repository. If it %finds that the changes added a new head to the repository, it %begins a merge, then (if the merge succeeded) commits the result %of the merge with an automatically-generated commit message. If %no new heads were added, it updates the working directory to the %new tip changeset. \hgext{fetch}$B%(%/%9%F%s%7%g%s$O$=$NL>$NDL$j$N?7$7$$%3%^%s%I(B\hgcmd{fetch} $B$rDI2C$9$k!%$3$N%(%/%9%F%s%7%g%s$O(B\hgopt{pull}{-u}$B$H(B\hgcmd{merge}$B$*$h$S(B \hgcmd{commit}$B$rAH$_9g$o$;$?F/$-$r$9$k!%$3$N%(%/%9%F%s%7%g%s$O$^$:B>$N%j(B $B%]%8%H%j$+$iJQ99$r(Bpull$B$7!$%j%]%8%H%j$K?7$7$$%X%C%I$,DI2C$5$l$?>l9g$O%^!<(B $B%8$r9T$$!$!J%^!<%8$,@.8y$7$?>l9g!K%^!<%87k2L$r<+F0E*$K@8@.$5$l$?%3%_%C%H(B $B%a%C%;!<%8$H6&$K%3%_%C%H$9$k!%?7$?$J%X%C%I$,DI2C$5$l$J$+$C$?>l9g$O?7$?$J(B tip$B%A%'%s%8%;%C%H$X%o!<%-%s%0%G%#%l%/%H%j$r99?7$9$k!%(B %Enabling the \hgext{fetch} extension is easy. Edit the %\sfilename{.hgrc} in your home directory, and either go to the %\rcsection{extensions} section or create an \rcsection{extensions} %section. Then add a line that simply reads ``\Verb+fetch +''. \hgext{fetch}$B%(%/%9%F%s%7%g%s$O4JC1$KM-8z$K$9$k$3$H$,$G$-$k!%%[!<%`%G%#%l(B $B%/%H%j$N(B\sfilename{.hgrc}$B%U%!%$%k$rJT=8$7!$(B\rcsection{extensions}$B%;%/%7%g(B $B%s$K(B``\Verb+fetch +''$B$H$$$&9T$rDI2C$9$l$P$h$$!%(B \begin{codesample2} [extensions] fetch = \end{codesample2} %(Normally, the right-hand side of the ``\texttt{=}'' would indicate %where to find the extension, but since the \hgext{fetch} extension is in %the standard distribution, Mercurial knows where to search for it.) $B!JDL>o!$1&JU$N(B``\texttt{=}''$B$O%(%/%9%F%s%7%g%s$NCV$+$l$?>l=j$rI=$9(B $B$,!$(B\hgext{fetch}$B%(%/%9%F%s%7%g%s$OI8=`G[I[J*$K4^$^$l$k$?$a!$(BMercurial$B$O(B $B$=$N=j:_$r$9$G$KCN$C$F$$$k!%!K(B %%% Local Variables: %%% mode: yatex %%% TeX-master: "00book" %%% End: