hgbook
changeset 122:3af28630fe8c
How to goodbye depression by reverting one thousand times daily.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Wed Nov 15 16:57:29 2006 -0800 (2006-11-15) |
parents | 9094c9fda8ec |
children | f954c6f6eaa1 |
files | en/Makefile en/examples/daily.revert en/undo.tex |
line diff
1.1 --- a/en/Makefile Wed Nov 15 15:59:41 2006 -0800 1.2 +++ b/en/Makefile Wed Nov 15 16:57:29 2006 -0800 1.3 @@ -45,6 +45,7 @@ 1.4 daily.copy \ 1.5 daily.files \ 1.6 daily.rename \ 1.7 + daily.revert \ 1.8 hook.msglen \ 1.9 hook.simple \ 1.10 hook.ws \
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/en/examples/daily.revert Wed Nov 15 16:57:29 2006 -0800 2.3 @@ -0,0 +1,75 @@ 2.4 +#!/bin/bash 2.5 + 2.6 +hg init a 2.7 +cd a 2.8 +echo 'original content' > file 2.9 +hg ci -Ama 2.10 + 2.11 +#$ name: modify 2.12 + 2.13 +cat file 2.14 +echo unwanted change >> file 2.15 +hg diff file 2.16 + 2.17 +#$ name: unmodify 2.18 + 2.19 +hg status 2.20 +hg revert file 2.21 +cat file 2.22 + 2.23 +#$ name: status 2.24 + 2.25 +hg status 2.26 +cat file.orig 2.27 + 2.28 +#$ name: 2.29 + 2.30 +rm file.orig 2.31 + 2.32 +#$ name: add 2.33 + 2.34 +echo oops > oops 2.35 +hg add oops 2.36 +hg status oops 2.37 +hg revert oops 2.38 +hg status 2.39 + 2.40 +#$ name: 2.41 + 2.42 +rm oops 2.43 + 2.44 +#$ name: remove 2.45 + 2.46 +hg remove file 2.47 +hg status 2.48 +hg revert file 2.49 +hg status 2.50 +ls file 2.51 + 2.52 +#$ name: missing 2.53 + 2.54 +rm file 2.55 +hg status 2.56 +hg revert file 2.57 +ls file 2.58 + 2.59 +#$ name: copy 2.60 + 2.61 +hg copy file new-file 2.62 +hg revert new-file 2.63 +hg status 2.64 + 2.65 +#$ name: 2.66 + 2.67 +rm new-file 2.68 + 2.69 +#$ name: rename 2.70 + 2.71 +hg rename file new-file 2.72 +hg revert new-file 2.73 +hg status 2.74 + 2.75 +#$ name: rename-orig 2.76 + 2.77 +hg revert file 2.78 +hg status
3.1 --- a/en/undo.tex Wed Nov 15 15:59:41 2006 -0800 3.2 +++ b/en/undo.tex Wed Nov 15 16:57:29 2006 -0800 3.3 @@ -8,7 +8,7 @@ 3.4 capable features that will help you to isolate the sources of 3.5 problems, and to handle them appropriately. 3.6 3.7 -\section{Easily recovered errors} 3.8 +\section{Erasing local history} 3.9 3.10 \subsection{The accidental commit} 3.11 3.12 @@ -46,9 +46,10 @@ 3.13 \interaction{rollback.rollback} 3.14 Notice that the changeset is no longer present in the repository's 3.15 history, and the working directory once again thinks that the file 3.16 -\filename{a} is modified. The changeset has been completely erased. 3.17 -I can now safely \hgcmd{add} the file \filename{b}, and rerun my 3.18 -commit. 3.19 +\filename{a} is modified. The commit and rollback have left the 3.20 +working directory exactly as it was prior to the commit; the changeset 3.21 +has been completely erased. I can now safely \hgcmd{add} the file 3.22 +\filename{b}, and rerun my commit. 3.23 \interaction{rollback.add} 3.24 3.25 \subsection{The erroneous pull} 3.26 @@ -111,6 +112,75 @@ 3.27 roll back again in that repository until you perform another commit or 3.28 pull. 3.29 3.30 +\section{Reverting the mistaken change} 3.31 + 3.32 +If you make a modification to a file, and decide that you really 3.33 +didn't want to change the file at all, the \hgcmd{revert} command is 3.34 +the one you'll need. It looks at the changeset that's the parent of 3.35 +the working directory, and restores the contents of the file to their 3.36 +state as of that changeset. (That's a long-winded way of saying that, 3.37 +in the normal case, it undoes your modifications.) 3.38 + 3.39 +Let's illustrate how the \hgcmd{revert} command works with yet another 3.40 +small example. We'll begin by modifying a file that Mercurial is 3.41 +already tracking. 3.42 +\interaction{daily.revert.modify} 3.43 +If we don't want that change, we can simply \hgcmd{revert} the file. 3.44 +\interaction{daily.revert.unmodify} 3.45 +The \hgcmd{revert} command provides us with an extra degree of safety 3.46 +by saving our modified file with a \filename{.orig} extension. 3.47 +\interaction{daily.revert.status} 3.48 + 3.49 +\subsection{File management errors} 3.50 +\label{sec:undo:mgmt} 3.51 + 3.52 +The \hgcmd{revert} command is useful for more than just modified 3.53 +files. It lets you reverse the results of all of Mercurial's file 3.54 +management commands---\hgcmd{add}, \hgcmd{remove}, and so on. 3.55 + 3.56 +If you \hgcmd{add} a file, then decide that in fact you don't want 3.57 +Mercurial to track it, use \hgcmd{revert} to undo the add. Don't 3.58 +worry; Mercurial will not modify the file in any way. It will just 3.59 +``unmark'' the file. 3.60 +\interaction{daily.revert.add} 3.61 + 3.62 +Similarly, if you ask Mercurial to \hgcmd{remove} a file, you can use 3.63 +\hgcmd{revert} to restore it to the contents it had as of the parent 3.64 +of the working directory. 3.65 +\interaction{daily.revert.remove} 3.66 +This works just as well for a file that you deleted by hand, without 3.67 +telling Mercurial (recall that in Mercurial terminology, this kind of 3.68 +file is called ``missing''). 3.69 +\interaction{daily.revert.missing} 3.70 + 3.71 +If you revert a \hgcmd{copy}, the copied-to file remains in your 3.72 +working directory afterwards, unmodified. 3.73 +\interaction{daily.revert.copy} 3.74 + 3.75 +\subsubsection{A slightly special case: reverting a rename} 3.76 + 3.77 +If you \hgcmd{rename} a file, there is one small detail that 3.78 +you should remember. When you \hgcmd{revert} a rename, it's not 3.79 +enough to provide the name of the renamed-to file, as you can see 3.80 +here. 3.81 +\interaction{daily.revert.rename} 3.82 +As you can see from the output of \hgcmd{status}, the renamed-to file 3.83 +is no longer identified as added, but the renamed-\emph{from} file is 3.84 +still removed! This is counter-intuitive (at least to me), but at 3.85 +least it's easy to deal with. 3.86 +\interaction{daily.revert.rename-orig} 3.87 +So remember, to revert a \hgcmd{rename}, you must provide \emph{both} 3.88 +the source and destination names. 3.89 + 3.90 +(By the way, if you rename a file, then modify the renamed-to file, 3.91 +then revert both components of the rename, when Mercurial restores the 3.92 +file that was removed as part of the rename, it will be unmodified. 3.93 +If you need the modifications in the renamed-to file to show up in the 3.94 +renamed-from file, don't forget to copy them over.) 3.95 + 3.96 +These fiddly aspects of reverting a rename arguably consitute a small 3.97 +bug in Mercurial. 3.98 + 3.99 %%% Local Variables: 3.100 %%% mode: latex 3.101 %%% TeX-master: "00book"