Mercurial > hgbook
annotate en/daily.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 | 7ac85766db0f |
children | 6b0f4498569e |
rev | line source |
---|---|
42
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1 \chapter{Mercurial in daily use} |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2 \label{chap:daily} |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
3 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
4 \section{Routine file management tasks} |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
5 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
6 \subsection{Telling Mercurial which files to track} |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
7 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
8 Mercurial does not work with files in your repository unless you tell |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
9 it to manage them. The \hgcmd{status} command will tell you which |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
10 files Mercurial doesn't know about; it uses a ``\texttt{?}'' to |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
11 display such files. |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
12 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
13 To tell Mercurial to track a file, use the \hgcmd{add} command. Once |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
14 you have added a file, the entry in the output of \hgcmd{status} for |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
15 that file changes from ``\texttt{?}'' to ``\texttt{A}''. |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
16 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
17 After you run a \hgcmd{commit}, the files that you added before the |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
18 commit will no longer be listed in the output of \hgcmd{status}. The |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
19 reason for this is that \hgcmd{status} only tells you about |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
20 ``interesting'' files by default. If you have a repository that |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
21 contains thousands of files, you will rarely want to know about files |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
22 that Mercurial is tracking, but that have not changed. (You can still |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
23 get this information; we'll return to this later.) |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
24 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
25 \begin{figure}[ht] |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
26 \interaction{daily.files.add} |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
27 \caption{Telling Mercurial to track a file} |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
28 \label{ex:daily:add} |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
29 \end{figure} |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
30 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
31 Once you add a file, Mercurial will track every change you make to it |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
32 until you either remove or rename the file. |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
33 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
34 \subsubsection{Aside: Mercurial tracks files, not directories} |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
35 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
36 Mercurial does not track directory information. Instead, it tracks |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
37 the path to a file, and creates directories along a path when it needs |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
38 to. This sounds like a trivial distinction, but it has one minor |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
39 practical consequence: it is not possible to represent a completely |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
40 empty directory in Mercurial. |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
41 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
42 Empty directories are rarely useful, and there are unintrusive |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
43 workarounds that you can use to achieve an appropriate effect. The |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
44 developers of Mercurial thus felt that the complexity that would be |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
45 required to manage empty directories was not worth the limited benefit |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
46 this feature would bring. |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
47 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
48 If you need an empty directory in your repository, there are a few |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
49 ways to achieve this. One is to create a directory, then \hgcmd{add} a |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
50 ``hidden'' file to that directory. On Unix-like systems, any file |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
51 name that begins with a period (``\texttt{.}'') is treated as hidden |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
52 by most commands and GUI tools. This approach is illustrated in |
43 | 53 figure~\ref{ex:daily:hidden}. |
42
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
54 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
55 \begin{figure}[ht] |
43 | 56 \interaction{daily.files.hidden} |
57 \caption{Simulating an empty directory using a hidden file} | |
58 \label{ex:daily:hidden} | |
42
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
59 \end{figure} |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
60 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
61 Another way to tackle a need for an empty directory is to simply |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
62 create one in your automated build scripts before they will need it. |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
63 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
64 \subsection{How to stop tracking a file} |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
65 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
66 If you decide that a file no longer belongs in your repository, use |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
67 the \hgcmd{remove} command; this deletes the file, and tells Mercurial |
43 | 68 to stop tracking it. A removed file is represented in the output of |
69 \hgcmd{status} with a ``\texttt{R}''. | |
42
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
70 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
71 You might wonder why Mercurial requires you to explicitly tell it that |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
72 you are deleting a file. Earlier during the development of Mercurial, |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
73 you could simply delete a file however you pleased; Mercurial would |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
74 notice automatically when you next ran a \hgcmd{commit}, and stop |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
75 tracking the file. In practice, this made it too easy to accidentally |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
76 stop Mercurial from tracking a file. |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
77 |
43 | 78 Mercurial considers a file that you have deleted, but not used |
79 \hgcmd{remove} to delete, to be \emph{missing}. A missing file is | |
80 represented with ``\texttt{!}'' in the output of \hgcmd{status}. | |
81 Other Mercurial commands will not do anything with missing files. | |
82 | |
83 If you have a missing file in your repository, you can run | |
84 \hgcmdargs{remove}{\hgopt{remove}{--after}} later on, to tell | |
85 Mercurial that you deleted the file. If you deleted the file by | |
86 accident, use \hgcmdargs{revert}{\emph{filename}} to restore the file | |
87 to its last committed state. | |
42
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
88 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
89 \subsection{Useful shorthand---adding and removing files in one step} |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
90 |
43 | 91 Mercurial offers a combination command, \hgcmd{addremove}, that adds |
92 untracked files and marks missing files as removed. The | |
93 \hgcmd{commit} command also provides a \hgopt{commit}{-A} option that | |
94 performs an add-and-remove, immediately followed by a commit. This | |
95 lets you replace the following command sequence: | |
96 \begin{codesample2} | |
97 hg add | |
98 hg remove --after | |
99 hg commit | |
100 \end{codesample2} | |
101 with a single command, \hgcmdargs{commit}{\hgopt{commit}{-A}}. | |
42
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
102 |
43 | 103 \subsection{Renaming files} |
104 | |
105 To rename a file that is tracked by Mercurial, use the \hgcmd{rename} | |
106 command. This command behaves similarly to the Unix \command{mv} | |
107 command. If the last argument is a directory, it moves all prior | |
108 arguments into that directory. Otherwise, it renames a single file or | |
109 directory to the name given in the last argument. | |
110 | |
111 As with \hgcmd{remove}, you can tell Mercurial about a rename after | |
112 the fact using the \hgopt{remove}{--after} option. | |
113 | |
114 The na\"{i}ve way to ``rename'' a file is simply to rename the file | |
115 yourself, \hgcmd{remove} the old name, and \hgcmd{add} the new name. | |
116 However, if you do this, Mercurial will not know that there was any | |
117 relationship between the files in question, and it will not be able to | |
118 merge | |
119 | |
120 \subsection{Copying files} | |
121 | |
122 You can copy a file in two ways using mercurial. If you simply copy a | |
123 file and then \hgcmd{add} the new file, Mercurial will not know that | |
124 there was any relationship between the two files. However, if you | |
42
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
125 |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
126 %%% Local Variables: |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
127 %%% mode: latex |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
128 %%% TeX-master: "00book" |
cbfa08bcf181
Start the "Mercurial in daily use" chapter.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
129 %%% End: |