The comment buffer is a plain-text buffer. However, each time you commit a comment buffer, the contents are saved to a new slot in a ring of comment buffers. You can cycle backwards in the ring with M-pand forward with M-n, or you can search for text backwards in the ring with M-rand forward with M-s. By design, these are the same keys you can use to navigate an Emacs minibuffer command history. By far the most commonly used of these commands is M-p. Being able to recall and edit the last change comment is often useful since it's common to make a series of related changes.
To give you the flavor of the other things VC can do for you, Table 12-1provides a summary of VC commands. Each one will be explained in detail, but you can probably guess some of their actions from the command names.
Table 12-1. VC commands
Keystrokes |
Command name |
Action |
C-x v v |
vc-next-action |
Go to the next logical version control state. |
C-x v d |
vc-directory |
Show all registered files beneath a directory. |
C-x v = |
vc-diff |
Generate a version difference report. |
C-x v u |
vc-revert-buffer |
Throw away changes since the last checked-in revision. |
C-x v ~ |
vc-version-other-window |
Retrieve a given revision in another window. |
C-x v l |
vc-print-log |
Display a file's change comments and history. |
C-x v i |
vc-register |
Register a file for version control. |
C-x v h |
vc-insert-headers |
Insert version control headers in a file. |
C-x v r |
vc-retrieve-snapshot |
Check out a named project snapshot. |
C-x v s |
vc-create-snapshot |
Create a named project snapshot. |
C-x v c |
vc-cancel-version |
Throw away a saved revision. |
C-x v a |
vc-update-change-log |
Update a GNU-style ChangeLog file. |
These commands are ordered in the table roughly by decreasing frequency of use. This is also the order in which we'll describe them in the following sections. All VC commands have the common prefix C-x v. Your fingers will learn this prefix quickly, and all you usually have to remember is the single command suffix. Two minor commands, vc-rename-fileand vc-clear-context, are not bound to keys. They are explained later on.
VC grabs a bit of the mode line for each buffer visiting a registered file and tries to use it to keep you informed of the version control state of that file. You'll notice that when a buffer is visiting a version-controlled file, the mode tags part of the mode line (shown in parentheses) shows the name of your version control system and a revision number for the file.
When those two parts are separated by a dash, the file is not yet checked out; when they're separated by a colon, the file has been checked out, and the revision number is the one the file had when you checked it out. Note that since most people use concurrent version control systems these days, in which you don't check files out or obtain locks, you can think of the dash as meaning unmodified, while the colon means there have been changes that are not yet committed to the repository.
If you don't see these indicators, the file isn't registered yet. These three states are illustrated in Figure 12-3.
Figure 12-3. Mode lines showing a file that is not under version control, one that is unchanged with respect to the repository, and one that has had changes saved but not yet committed.
12.7 Which Version Control System?
We said earlier that VC uses any of a number of version control systems (more may be added in the future). It chooses which to use for any given file by looking for a corresponding master file— that is, a file containing a change history.
If you're using RCS, each of your project directories usually has a subdirectory in which RCS masters live. If you're using SCCS, there are SCCS subdirectories. CVS is a little trickier; your project directory has a CVS subdirectory with control information in it, but CVS masters are typically kept in one central repository directory, the location of which is typically given by the CVSROOT environment variable, and will likely be on another machine completely, using the pserver network protocol. Subversion, too, uses a separate server machine to store the revision repository; it generally uses WebDAV over HTTP for its transactions. Your local Subversion master files are kept in a subdirectory named .svn .
If VC can't find a master in any of these special directories, it looks for a master in the same directory as your work file (so you don't have to create SCCS or RCS directories if you don't mind your work directories being cluttered with masters). VC checks each of these possibilities (so you can actually use more than one system in the same directory, although we don't recommend it).
If VC can't find a master anywhere, it looks for an RCS , SCCS , CVS , or .svn directory. The order in which these are attempted is controlled by the variable vc-handled-backends, described in "Customizing VC" later in this chapter. The first one it finds tells it which version control system to register new files with. If it can't find any of these directories, and you tell it to register a file, it assumes you want to use RCS and creates the master right alongside your work file.
To find out which of SCCS, RCS, CVS, or Subversion is available on your system, simply execute the commands comb, rcs, cvs, and svnrespectively, with no arguments. If you see an error or usage message, the corresponding system is ready to use; if you see command not found
, it's not.
12.8 Individual VC Commands
We've already explained what the main command, vc-next-action, does. Now we'll describe each of VC's other commands in detail. We have chosen the order of these descriptions to take you from frequently used and simpler commands to rarer and more complex ones.
You can, accordingly, read to the end of chapter or bail out at any point if you think you've learned all you need to. But try to persevere because you may find that the descriptions of the less common commands give you some new ideas about how to track and organize your project files.
12.8.1 Working with Groups and Subtrees of Files
Usually, the projects you want to put under version control have more than one file; it's normal for them to contain all the files under a specific directory and subdirectory. Therefore, seeing a list of all version-controlled files beneath the current working directory is often useful. Being able to perform an operation on all of them en masse is even more useful.
VC mode supports this directly. The command C-x v d(for vc-directory) puts you in a buffer running a customized Dired (directory editing) mode, which lists all registered files under the current directory, indicating which, if any, are checked out and who has locked them. The status field in this listing is automatically kept up to date by check-in and check-out operations.
Читать дальше