12.12 Using VC Effectively
We urge those of you with prior version control experience to heed the following maxim: to use VC effectively, check in your changes early and often! Of course, when you are working as part of a team of developers, you do need to take care to check in only a consistent and working set of files each time. There's nothing quite equal to the frustration of discovering that you can no longer compile and test your own code because someone else has checked in a fragmentary or broken piece of theirs.
If you're used to version control interfaces that are as clumsy and difficult as bare SCCS, RCS, or—to a lesser extent—CVS, your reflexes may prevent you from getting the most leverage out of VC. You probably won't commit often; you're not used to being able to instantly get status reports on a whole subtree of files.
It's worth a little thought and effort to reeducate yourself. You'll find that, instead of being an irritating minor chore, version control under VC can be tremendously liberating. By checking changes in often, you'll find you can afford to experiment more, because you'll know how to revert to a known good state quickly if need be.
12.13 Comparing with Ediff
In working with any version control system, you sometimes want to compare different revisions of a file. Often you're interested in what's changed in the current working revision, but sometimes you're after more historical information. The most challenging situation arises when an optimistic strategy like CVS is proved wrong, and you need to merge incompatible changes made by multiple developers to the same section of a file.
We've already described vc-diff, VC's built-in facility for helping with these tasks. We would be remiss, however, if we did not introduce you to Ediff, an even more powerful facility that is available in current releases of GNU Emacs. Ediff is extremely rich; it almost feels like another program that "takes over" your Emacs session for a while. Full coverage would require an entire chapter, or perhaps even its own handbook, but this introduction will get you started and point you at the built-in manual if you want to delve deeper.
For the most part, you launch Ediff as an independent entity rather than having it invoked automatically by the version control interface. The exception (as mentioned above) is if you ask Emacs for help resolving conflicts when they occur during a check-in operation or manually invoke vc-resolve-conflictswhile visiting a buffer containing such conflicts.
If you want to use Ediff to compare two nonconflicting revisions of a file, choose Tools → Compare (Ediff) → File with revision, or type M-x ediff-revision Enter. Ediff prompts you for the file you'd like to compare (defaulting to the file associated with the current buffer), and the revision(s) you'd like to compare, defaulting to the version last checked in and the current state of the buffer. (Ediff can also be used for many tasks outside the context of version control systems; you might want to explore the options on the Compare (Ediff) menu on a rainy day.)
The first time you invoke Ediff, you will probably find it disorienting. In addition to the expected pair of buffers showing you the two files or revisions being compared, it pops open a small "control window" (see Figure 12-4) in which you type commands. In its default configuration, this is a separate operating system window (or what Emacs refers to as a "frame"). For Ediff commands to work, this window must have keyboard focus (must show as being the currently active window as far as the operating system is concerned). This is different from almost any other situation in Emacs, in that you're looking at and manipulating content in one frame while a second frame has focus.
Figure 12-4. The Ediff control window in its default state (Mac OS X)
In its default configuration, the control window is designed to be small enough not to get in the way on smaller displays. The problem is that you might not even notice it, let alone realize what it's for! In addition to being the place you type Ediff commands, this small window shows you where you are in the difference list (in this case, before the first of seven differences), and reminds you that you can type ?to get some more help. As a new Ediff user, we strongly recommend that you type ?each time you fire it up to expand the control window into the larger, Quick Help mode, shown in Figure 12-5.
Figure 12-5. The Ediff control window showing Quick Help (Mac OS X)
In addition to the control window, you'll see the differences between the files you're comparing inside the frame you were previously using for editing. If you're looking at a large file, none of the differences might be visible initially. You can jump to the first difference by typing nor pressing the space bar, as suggested by the quick help window. (Remember that for any of the Ediff commands to work, the control/quick help window must have keyboard focus.) The displayed differences will look something like Figure 12-6.
Figure 12-6. Differences displayed by Ediff
Ediff centers the difference regions within each buffer, and marks the changed lines with color, further emphasizing the specific portions of the lines which have changed to help attract visual attention to the differences. This is much more helpful than the traditional diff mode, making it worthwhile learning the strange new interface.
The basic way to use Ediff is to scroll through the buffers, seeing what has changed between them. The normal Emacs "browsing" keys ( Spaceto move forward, Delto move backward) are bound in the control window to take you through the differences one by one. Pressing n(next) and p(previous) has the same effect. If you want to go to a specific difference, you can type a number followed by j(jump) to move immediately to that difference. To scroll up or down by pages rather than by differences you can use vto move forward and Vto move backward. If your buffers contain wide lines, you can also type <and >to scroll left and right. If you'd like to view the buffers side by side rather than one above the other, type |(vertical bar). Typing this a second time returns to showing the buffers vertically. To reduce the need to scroll horizontally, you can make the comparison window as wide as possible by typing m(this is also a toggle; typing it again returns the window to its previous width). This command might cause the control window to lose focus, forcing you to click back into it before issuing the next Ediff command. (See "Recovering from Confusion" later in this chapter.) Important commands available in Ediff are summarized in Table 12-2.
Table 12-2. Ediff commands
Keystrokes |
Command name |
Action |
Spaceor n |
ediff-next-difference |
Move to the next difference between the files. |
Delor p |
ediff-previous-difference |
Move to the preceding difference between the files. |
j |
ediff-jump-to-difference |
Go to the difference specified as a numeric prefix argument. |
vor C-v |
ediff-scroll-vertically |
Move forward one page in both buffers. |
Vor M-v |
ediff-scroll-vertically |
Move backward one page in both buffers. |
< |
ediff-scroll-horizontally |
Scroll each buffer to the left. |
> |
ediff-scroll-horizontally |
Scroll each buffer to the right. |
|(vertical bar) |
ediff-toggle-split |
Switch between viewing the buffers one above the other and side-by-side. |
m |
ediff-toggle-wide-display |
Toggle between normal frame size and making it as wide as possible. |
a |
ediff-copy-A-to-B |
Copy the version of the current difference found in buffer A to buffer B. |
b |
ediff-copy-B-to-A |
Copy the version of the current difference found in buffer B to buffer A. |
r aor r b |
ediff-restore-diff |
Restore the current difference in buffer A (or B) to the way it was before copying from the other buffer. |
Aor B |
ediff-toggle-read-only |
Switch the specified buffer into (or out of) read-only mode. |
g aor g b |
ediff-jump-to-difference-at-point |
Recenter the comparison buffers on the difference nearest to your current location (point) in the specified buffer. |
C-l |
ediff-recenter |
Restore the comparison display so that the highlighted regions of all buffers being compared are visible; useful if you've been doing something else and want to get back to comparing. |
! |
ediff-update-diffs |
Recalculate and redisplay the highlighted regions; useful if you've manually made extensive changes to a buffer. |
w aor w b |
ediff-save-buffer |
Save the specified buffer to disk. |
E |
ediff-documentation |
Open the manual for Ediff. |
z |
ediff-suspend |
Close the Ediff control window, but leave the session active so you can resume it later. |
q |
ediff-quit |
Close the Ediff window and end this comparison session. |
Читать дальше