comparison ja/undo.tex @ 291:504f23b4f625

started japanese translation
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Thu, 07 Feb 2008 15:52:15 +0900
parents b0db5adf11c1
children b8105146706f
comparison
equal deleted inserted replaced
290:b0db5adf11c1 291:504f23b4f625
1 \chapter{Finding and fixing your mistakes} 1 %\chapter{Finding and fixing your mistakes}
2 \chapter{$B%_%9$NH/8+$H=$@5(B}
2 \label{chap:undo} 3 \label{chap:undo}
3 4
4 To err might be human, but to really handle the consequences well 5 %To err might be human, but to really handle the consequences well
5 takes a top-notch revision control system. In this chapter, we'll 6 %takes a top-notch revision control system. In this chapter, we'll
6 discuss some of the techniques you can use when you find that a 7 %discuss some of the techniques you can use when you find that a
7 problem has crept into your project. Mercurial has some highly 8 %problem has crept into your project. Mercurial has some highly
8 capable features that will help you to isolate the sources of 9 %capable features that will help you to isolate the sources of
9 problems, and to handle them appropriately. 10 %problems, and to handle them appropriately.
10 11
11 \section{Erasing local history} 12 $B%j%S%8%g%s%3%s%H%m!<%k%7%9%F%`$K$O?M$NHH$7$?4V0c$$$r$&$^$/=hM}$9$k5!G=$,(B
12 13 $B5a$a$i$l$F$$$k!%$3$N>O$G$O!$%W%m%8%'%/%H$K5/$3$jF@$kLdBj$N2r7h$KMxMQ2DG=(B
13 \subsection{The accidental commit} 14 $B$J%F%/%K%C%/$K$D$$$F=R$Y$k!%(BMercurial$B$K$OLdBj$N$"$k%=!<%9$r@Z$jJ,$1!$=hM}(B
14 15 $B$9$k6/NO$J5!G=$,$"$k!%(B
15 I have the occasional but persistent problem of typing rather more 16
16 quickly than I can think, which sometimes results in me committing a 17
17 changeset that is either incomplete or plain wrong. In my case, the 18 %\section{Erasing local history}
18 usual kind of incomplete changeset is one in which I've created a new 19 \section{$B%m!<%+%k%R%9%H%j!<$r>C5n$9$k(B}
19 source file, but forgotten to \hgcmd{add} it. A ``plain wrong'' 20
20 changeset is not as common, but no less annoying. 21 %\subsection{The accidental commit}
21 22 \subsection{$B%"%/%7%G%s%H$K$h$k%3%_%C%H(B}
22 \subsection{Rolling back a transaction} 23
24 %I have the occasional but persistent problem of typing rather more
25 %quickly than I can think, which sometimes results in me committing a
26 %changeset that is either incomplete or plain wrong. In my case, the
27 %usual kind of incomplete changeset is one in which I've created a new
28 %source file, but forgotten to \hgcmd{add} it. A ``plain wrong''
29 %changeset is not as common, but no less annoying.
30
31 $BI.<T$K$O%?%$%T%s%0Cf$K9M$($k$h$j$b@h$K;X$,F0$$$F$7$^$&JJ$,0JA0$+$i$"$j!$(B
32 $B$?$^$K$3$l$,5/$-$k$H!$IT40A4$@$C$?$j4V0c$C$?FbMF$N%A%'%s%8%;%C%H$r%3%_%C(B
33 $B%H$7$F$7$^$&!%I.<T$N>l9g!$IT40A4$J%A%'%s%8%;%C%H$NE57?$O?7$7$$%=!<%9%U%!(B
34 $B%$%k$r:n@.$7$?$N$K(B\hgcmd{add}$B$rK:$l$k$3$H$G!$(B``$B4V0c$C$?FbMF(B''$B$N%3%_%C%H(B
35 $B$O$"$^$j5/$-$J$$$,!$$d$O$jF1$8$h$&$KLq2p$G$"$k!%(B
36
37
38 %\subsection{Rolling back a transaction}
39 \subsection{$B%H%i%s%6%/%7%g%s$N%m!<%k%P%C%/(B}
23 \label{sec:undo:rollback} 40 \label{sec:undo:rollback}
24 41
25 In section~\ref{sec:concepts:txn}, I mentioned that Mercurial treats 42 %In section~\ref{sec:concepts:txn}, I mentioned that Mercurial treats
26 each modification of a repository as a \emph{transaction}. Every time 43 %each modification of a repository as a \emph{transaction}. Every time
27 you commit a changeset or pull changes from another repository, 44 %you commit a changeset or pull changes from another repository,
28 Mercurial remembers what you did. You can undo, or \emph{roll back}, 45 %Mercurial remembers what you did. You can undo, or \emph{roll back},
29 exactly one of these actions using the \hgcmd{rollback} command. (See 46 %exactly one of these actions using the \hgcmd{rollback} command. (See
30 section~\ref{sec:undo:rollback-after-push} for an important caveat 47 %section~\ref{sec:undo:rollback-after-push} for an important caveat
31 about the use of this command.) 48 %about the use of this command.)
32 49
33 Here's a mistake that I often find myself making: committing a change 50 \ref{sec:concepts:txn}$B@a$G!$(BMercurial$B$O%j%]%8%H%j$X$N8D!9$NJQ99$r(B\emph{$B%H(B
34 in which I've created a new file, but forgotten to \hgcmd{add} it. 51 $B%i%s%6%/%7%g%s(B}$B$H$7$F07$&$H$$$&$3$H$r=R$Y$?!%(BMercurial$B$O!$JL$N%j%]%8%H%j(B
52 $B$X$N%A%'%s%8%;%C%H$N%3%_%C%H$dJQ99$N(Bpull$B$r5-21$7$F$$$k!%%f!<%6$O(Bundo$B$7$?(B
53 $B$j!$0l2s$K8B$j%"%/%7%g%s$r(B\hgcmd{rollback}$B%3%^%s%I$G(B\emph{$B%m!<%k%P%C%/(B}$B$9(B
54 $B$k$3$H$,$G$-$k!%(B($B$3$N%3%^%s%I$N=EMW$J@)Ls$K$D$$$F$O(B
55 \ref{sec:undo:rollback-after-push}$B$r;2>H$N$3$H!%(B)
56
57
58 %Here's a mistake that I often find myself making: committing a change
59 %in which I've created a new file, but forgotten to \hgcmd{add} it.
60 %\interaction{rollback.commit}
61 %Looking at the output of \hgcmd{status} after the commit immediately
62 %confirms the error.
63 %\interaction{rollback.status}
64 %The commit captured the changes to the file \filename{a}, but not the
65 %new file \filename{b}. If I were to push this changeset to a
66 %repository that I shared with a colleague, the chances are high that
67 %something in \filename{a} would refer to \filename{b}, which would not
68 %be present in their repository when they pulled my changes. I would
69 %thus become the object of some indignation.
70
71 $BI.<T$,NI$/5/$3$9%_%9$O!$?7$7$$%U%!%$%k$r:n@.$7$?%A%'%s%8%;%C%H$r%3%_%C%H(B
72 $B$9$k;~$K(B\hgcmd{add}$B$N<B9T$rK:$l$k$b$N$G$"$k!%(B
35 \interaction{rollback.commit} 73 \interaction{rollback.commit}
36 Looking at the output of \hgcmd{status} after the commit immediately 74 $B%3%_%C%H8e$N(B\hgcmd{status}$B$N=PNO$r8+$k$H!$D>$A$K%(%i!<$rI=<($7$F$$$k$3$H(B
37 confirms the error. 75 $B$,$o$+$k!%(B
38 \interaction{rollback.status} 76 \interaction{rollback.status}
39 The commit captured the changes to the file \filename{a}, but not the 77 $B%3%_%C%H$O(B\filename{a}$B$X$NJQ99$r4^$s$G$$$k$,!$(B\filename{b}$B$X$NJQ99$O4^$s(B
40 new file \filename{b}. If I were to push this changeset to a 78 $B$G$$$J$$!%$3$3$G;d$,F1N=$H6&M-$7$F$$$k%j%]%8%H%j$X%A%'%s%8%;%C%H$N%W%C%7%e(B
41 repository that I shared with a colleague, the chances are high that 79 $B$r9T$J$C$?$H$7$?$i!$H`$i$,JQ99$r%W%k$7$?;~!$(B\filename{a}$B$NCf$N2?$+$,H`$i(B
42 something in \filename{a} would refer to \filename{b}, which would not 80 $B$N%j%]%8%H%j$K4^$^$l$J$$(B\filename{b}$B$X$N;2>H$r9T$J$&2DG=@-$O9b$$!%$=$&$J$C(B
43 be present in their repository when they pulled my changes. I would 81 $B$?$iI.<T$OF1N=$NE\$j$rGc$&$3$H$K$J$k$@$m$&!%(B
44 thus become the object of some indignation. 82
45 83 %However, luck is with me---I've caught my error before I pushed the
46 However, luck is with me---I've caught my error before I pushed the 84 %changeset. I use the \hgcmd{rollback} command, and Mercurial makes
47 changeset. I use the \hgcmd{rollback} command, and Mercurial makes 85 %that last changeset vanish.
48 that last changeset vanish. 86 %\interaction{rollback.rollback}
87 %Notice that the changeset is no longer present in the repository's
88 %history, and the working directory once again thinks that the file
89 %\filename{a} is modified.The commit and rollback have left the
90 %working directory exactly as it was prior to the commit; the changeset
91 %has been completely erased. I can now safely \hgcmd{add} the file
92 %\filename{b}, and rerun my commit.
93 %\interaction{rollback.add}
94
95 $B$7$+$79%1?$K$b%A%'%s%8%;%C%H$r%W%C%7%e$9$kA0$K%(%i!<$K5$$E$$$?>l9g!$(B
96 \hgcmd{rollback}$B%3%^%s%I$r;HMQ$9$k$3$H$G(BMercurial$B$+$i:G8e$N99?7$r<h$j=|(B
97 $B$/$3$H$,$G$-$k!%(B
49 \interaction{rollback.rollback} 98 \interaction{rollback.rollback}
50 Notice that the changeset is no longer present in the repository's 99 $B%A%'%s%8%;%C%H$O$j$]$8$H$j$NMzNr$K$b$O$dB8:_$;$:!$%o!<%-%s%0%G%#%l%/%H%j(B
51 history, and the working directory once again thinks that the file 100 $B$N(B\filename{a}$B$OJQ99$5$l$?$HG'<1$5$l$k!%%3%_%C%H$7$F%m!<%k%P%C%/$9$k$H!$(B
52 \filename{a} is modified. The commit and rollback have left the 101 $B%o!<%-%s%0%G%#%l%/%H%j$O40A4$K%3%_%C%HA0$N>uBV$K$J$j!$%A%'%s%8%;%C%H$O40(B
53 working directory exactly as it was prior to the commit; the changeset 102 $BA4$K>C5n$5$l$k!%$3$N>uBV$G0BA4$K(B\hdcmd{add} \filename{b}$B$7!$$b$&0lEY(B
54 has been completely erased. I can now safely \hgcmd{add} the file 103 commit$B$9$k$3$H$,$G$-$k!%(B
55 \filename{b}, and rerun my commit. 104 \interaction{rollback.rollback}
56 \interaction{rollback.add} 105
57 106 %\subsection{The erroneous pull}
58 \subsection{The erroneous pull} 107 \subsection{$B8m$C$?%W%k(Bl}
59 108
60 It's common practice with Mercurial to maintain separate development 109 %It's common practice with Mercurial to maintain separate development
61 branches of a project in different repositories. Your development 110 %branches of a project in different repositories. Your development
62 team might have one shared repository for your project's ``0.9'' 111 %team might have one shared repository for your project's ``0.9''
63 release, and another, containing different changes, for the ``1.0'' 112 %release, and another, containing different changes, for the ``1.0''
64 release. 113 %release.
65 114
66 Given this, you can imagine that the consequences could be messy if 115 Mercurial$B$r;H$C$FJL!9$N3+H/%V%i%s%A$rJL!9$N%j%]%8%H%j$G4IM}$9$k$3$H$,$h$/(B
67 you had a local ``0.9'' repository, and accidentally pulled changes 116 $B$"$k!%$"$J$?$N3+H/%A!<%`$O%W%m%8%'%/%H$N%j%j!<%9(B0.9$B$N$?$a$K(B1$B$D$N6&M-%j%](B
68 from the shared ``1.0'' repository into it. At worst, you could be 117 $B%8%H%j$r;}$A!$%j%j!<%9(B1.0$B$N$?$a$K0[$J$kJQ99$r;}$C$?$b$&0l$DJL$N%j%]%8%H(B
69 paying insufficient attention, and push those changes into the shared 118 $B%j$r$b$C$F$$$k!%(B
70 ``0.9'' tree, confusing your entire team (but don't worry, we'll 119
71 return to this horror scenario later). However, it's more likely that 120 %Given this, you can imagine that the consequences could be messy if
72 you'll notice immediately, because Mercurial will display the URL it's 121 %you had a local ``0.9'' repository, and accidentally pulled changes
73 pulling from, or you will see it pull a suspiciously large number of 122 %from the shared ``1.0'' repository into it. At worst, you could be
74 changes into the repository. 123 %paying insufficient attention, and push those changes into the shared
75 124 %``0.9'' tree, confusing your entire team (but don't worry, we'll
76 The \hgcmd{rollback} command will work nicely to expunge all of the 125 %return to this horror scenario later). However, it's more likely that
77 changesets that you just pulled. Mercurial groups all changes from 126 %you'll notice immediately, because Mercurial will display the URL it's
78 one \hgcmd{pull} into a single transaction, so one \hgcmd{rollback} is 127 %pulling from, or you will see it pull a suspiciously large number of
79 all you need to undo this mistake. 128 %changes into the repository.
80 129
81 \subsection{Rolling back is useless once you've pushed} 130 $B$3$3$G$"$J$?$O8m$C$F%m!<%+%k$N(B0.9$B%j%]%8%H%j$K6&M-(B1.0$B%j%]%8%H%j$+$i%W%k$7(B
131 $B$?$H$9$k!%:G0-$N>l9g!$==J,Cm0U$;$:!$$3$l$r6&M-$N(B0.9$B%j%]%8%H%j$K=q$-La$7$F(B
132 $B$7$^$$!$3+H/%A!<%`A4BN$r:.Mp$5$;$F$7$^$&$3$H$,M-$jF@$k!%!J$3$N>l9g$I$&$9(B
133 $B$l$P$$$$$N$+$K$D$$$F$O8e=R$9$k!%!K$7$+$7(BMercurial$B$O%W%k85$N(BURL$B$H5?$$$r;}(B
134 $B$D$K==J,$J5pBg$JJQ99$rI=<($9$k$?$a!$B(:B$K5$$E$/2DG=@-$,9b$$!%(B
135
136 %The \hgcmd{rollback} command will work nicely to expunge all of the
137 %changesets that you just pulled. Mercurial groups all changes from
138 %one \hgcmd{pull} into a single transaction, so one \hgcmd{rollback} is
139 %all you need to undo this mistake.
140
141 \hgcmd{rollback}$B%3%^%s%I$r<B9T$9$l$P!$:#%W%k$7$?$P$+$j$N%A%'%s%8%;%C%H$r(B
142 $BA4$F>C5n$9$k$3$H$,$G$-$k!%(BMercurial$B$O0l2s(B\hgcmd{pull}$B$K$h$k%H%i%s%6%/%7%g(B
143 $B%s$G$b$?$i$5$l$?A4$F$N%A%'%s%8%;%C%H$r%0%k!<%W2=$7$F$$$k$N$G!$(B
144 \hgcmd{rollback}$B$r0lEY<B9T$9$k$@$1$G!$%_%9$rA4$F$d$jD>$9$3$H$,$G$-$k!%(B
145
146
147 %\subsection{Rolling back is useless once you've pushed}
148 \subsection{$B0lEY%W%C%7%e$7$?8e$G$O%m!<%k%P%C%/$G$-$J$$(B}
82 \label{sec:undo:rollback-after-push} 149 \label{sec:undo:rollback-after-push}
83 150
84 The value of the \hgcmd{rollback} command drops to zero once you've 151 %The value of the \hgcmd{rollback} command drops to zero once you've
85 pushed your changes to another repository. Rolling back a change 152 %pushed your changes to another repository. Rolling back a change
86 makes it disappear entirely, but \emph{only} in the repository in 153 %makes it disappear entirely, but \emph{only} in the repository in
87 which you perform the \hgcmd{rollback}. Because a rollback eliminates 154 %which you perform the \hgcmd{rollback}. Because a rollback eliminates
88 history, there's no way for the disappearance of a change to propagate 155 %history, there's no way for the disappearance of a change to propagate
89 between repositories. 156 %between repositories.
90 157
91 If you've pushed a change to another repository---particularly if it's 158 $BB>$N%j%]%8%H%j$KJQ99$r%W%C%7%e$7$?8e$G$O(B\hgcmd{rollback}$B$N2ACM$O%<%m$G$"(B
92 a shared repository---it has essentially ``escaped into the wild,'' 159 $B$k!%JQ99$r%m!<%k%P%C%/$9$k$3$H$K$h$C$FJQ99$O40A4$K>CLG$9$k$,!$$=$l$O$"$J(B
93 and you'll have to recover from your mistake in a different way. What 160 $B$?$,(B\hgcmd{rollback}$B$r<B9T$7$?%j%]%8%H%j$K8B$C$F$N$3$H$G$"$k!%%m!<%k%P%C(B
94 will happen if you push a changeset somewhere, then roll it back, then 161 $B%/$K$h$C$F!JJQ99$N!KMzNr<+BN$,$J$+$C$?$3$H$K$J$k$N$G!$JQ99$N>CLG$rB>$N%j(B
95 pull from the repository you pushed to, is that the changeset will 162 $B%]%8%H%j$KGH5Z$5$;$k<jCJ$O$J$$!%(B
96 reappear in your repository. 163
164 %If you've pushed a change to another repository---particularly if it's a
165 %shared repository---it has essentially ``escaped into the wild,'' and
166 %you'll have to recover from your mistake in a different way. What will
167 %happen if you push a changeset somewhere, then roll it back, then pull
168 %from the repository you pushed to, is that the changeset will reappear
169 %in your repository.
170
171 $B$b$7$"$J$?$,B>$N%j%]%8%H%j!JFC$K6&M-%j%]%8%H%j!K$KJQ99$r%W%C%7%e$7$F$$$k(B
172 $B$N$J$i!$:$$C$?;vBV$,5/$3$C$F$*$j!$JL$NJ}K!$G%_%9$+$iI|5l$9$kI,MW$,$"$k!%(B
173 $B%A%'%s%8%;%C%H$r$I$3$+$X%W%C%7%e$7$?8e$G%m!<%k%P%C%/$7!$%W%C%7%e@h$N%j%](B
174 $B%8%H%j$+$i:F$S%W%k$7$?>l9g!$%A%'%s%8%;%C%H$,%m!<%+%k%j%]%8%H%j$K:F$S8=$l(B
175 $B$k!%(B
97 176
98 (If you absolutely know for sure that the change you want to roll back 177 (If you absolutely know for sure that the change you want to roll back
99 is the most recent change in the repository that you pushed to, 178 is the most recent change in the repository that you pushed to,
100 \emph{and} you know that nobody else could have pulled it from that 179 \emph{and} you know that nobody else could have pulled it from that
101 repository, you can roll back the changeset there, too, but you really 180 repository, you can roll back the changeset there, too, but you really
102 should really not rely on this working reliably. If you do this, 181 should really not rely on this working reliably. If you do this,
103 sooner or later a change really will make it into a repository that 182 sooner or later a change really will make it into a repository that
104 you don't directly control (or have forgotten about), and come back to 183 you don't directly control (or have forgotten about), and come back to
105 bite you.) 184 bite you.)
106 185
107 \subsection{You can only roll back once} 186 $B!J$b$7%m!<%k%P%C%/$7$?$$%A%'%s%8%;%C%H$,%W%C%7%e@h$N%j%]%8%H%j$G:G?7$G$"(B
108 187 $B$j!$$+$D!$C/$b$=$l$r%W%k$7$F$$$J$$$3$H$,3N<B$G$"$k>l9g$O!$%W%C%7%e@h$N%j(B
109 Mercurial stores exactly one transaction in its transaction log; that 188 $B%]%8%H%j$G%m!<%k%P%C%/$9$k$3$H$,2DG=$@$,!$$3$NJ}K!$O3N<B$G$O$J$$$H$$$&$3(B
110 transaction is the most recent one that occurred in the repository. 189 $B$H$r4N$KL?$8$F$*$/$Y$-$G$"$k!%$3$NJ}K!$OD>@\%3%s%H%m!<%k$G$-$J$+$C$?$j!$(B
111 This means that you can only roll back one transaction. If you expect 190 $B$=$NJ}K!$rK:$l$F$7$^$C$?%j%]%8%H%j$X$NJQ99$N=$@5$K$O;H$($J$$!%!K(B
112 to be able to roll back one transaction, then its predecessor, this is 191
113 not the behaviour you will get. 192
193 %\subsection{You can only roll back once}
194 \subsection{$B%m!<%k%P%C%/$O0l2s$N$_(B}
195
196 %Mercurial stores exactly one transaction in its transaction log; that
197 %transaction is the most recent one that occurred in the repository.
198 %This means that you can only roll back one transaction. If you expect
199 %to be able to roll back one transaction, then its predecessor, this is
200 %not the behaviour you will get.
201 %\interaction{rollback.twice}
202 %Once you've rolled back one transaction in a repository, you can't
203 %roll back again in that repository until you perform another commit or
204 %pull.
205
206 Mercurial$B$O%H%i%s%6%/%7%g%s%m%0$K$=$N%j%]%8%H%j$K5/$3$C$?:G$b?7$7$$%H%i%s(B
207 $B%6%/%7%g%s0l2sJ,$N$_$r5-O?$7$F$$$k!%%m!<%k%P%C%/0l2sKh$K0l$DA0$N%j%S%8%g(B
208 $B%s$KLa$k$o$1$G$O$J$$!%(B
114 \interaction{rollback.twice} 209 \interaction{rollback.twice}
115 Once you've rolled back one transaction in a repository, you can't 210 $B%j%]%8%H%j$J$$$G0lEY%m!<%k%P%C%/$7$?$i!$JL$N%3%_%C%H$r$9$k$+%W%k$r$9$k$^(B
116 roll back again in that repository until you perform another commit or 211 $B$G%m!<%k%P%C%/$O$G$-$J$$!%(B
117 pull. 212
118 213
119 \section{Reverting the mistaken change} 214 %\section{Reverting the mistaken change}
215 \section{$B4V0c$C$?JQ99$r85$KLa$9(B}
120 216
121 If you make a modification to a file, and decide that you really 217 If you make a modification to a file, and decide that you really
122 didn't want to change the file at all, and you haven't yet committed 218 didn't want to change the file at all, and you haven't yet committed
123 your changes, the \hgcmd{revert} command is the one you'll need. It 219 your changes, the \hgcmd{revert} command is the one you'll need. It
124 looks at the changeset that's the parent of the working directory, and 220 looks at the changeset that's the parent of the working directory, and
756 Even if you end up ``early'' by thousands of changesets or months of 852 Even if you end up ``early'' by thousands of changesets or months of
757 history, you will only add a handful of tests to the total number that 853 history, you will only add a handful of tests to the total number that
758 \hgcmd{bisect} must perform, thanks to its logarithmic behaviour. 854 \hgcmd{bisect} must perform, thanks to its logarithmic behaviour.
759 855
760 %%% Local Variables: 856 %%% Local Variables:
761 %%% mode: latex 857 %%% mode: yatex
762 %%% TeX-master: "00book" 858 %%% TeX-master: "00book"
763 %%% End: 859 %%% End: