Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 14: Finding Differences Between Files

Previous HourNext Hour

Sections in this Hour:

 

Merging Files


In case you have two files that you want to merge, but none of the files are allowed to be overwritten, you should use one of the functions ediff-merge-files, ediff-merge-buffers, ediff-merge-files-with-ancestor, or ediff-merge-buffers-with- ancestor. The first two ask for two files or buffers to merge, while the later two ask for two functions or buffers to merge and a common ancestor.

Caution - Please be aware that the functions called emerge-files and emerge-buffers do similar jobs to the Ediff equivalents, but are much older and more primitive. When you have Ediff, you will never want to use these functions.


With a common ancestor Emacs can decide which part is the modified one, when a diff exists between the two buffers. Both parts can be modified.

Merging Without an Ancestor

In Figure 14.5 you can see the Emacs interface to ediff-merge-buffers.

Figure 14.5
The Emacs interface to ediff-merge-buffers.

There are several different ways Emacs can merge the files for you initially. That is the default action taken to insert some text in the merge buffer before asking you what to do. It might as default expect that the content of buffer A is the text to be used. Likewise it might use the text from buffer B. Finally it might merge the text as can be seen in Figure 14.5. The default action can be specified by pressing & (the ampersand).

If you do not agree with the default action that Emacs has taken, you can press a to use the content of buffer A, b to use the content of buffer B, or + to insert the content of the two buffers merged (like in Figure 14.5). If you want to undo one of these commands for the given diff, press r. (Just like with the Ediff commands.)

When text has been inserted in merged form, you can edit the merge buffer to be like you want it to.

Merging with an Ancestor

Merging using a common ancestor is much like merging without. There are a few differences, however. First, Emacs now has a chance to guess which buffer contains the modification. This means that in the cases where one of the buffers is equal to the ancestor, Emacs simply uses the content of the other buffers as the difference. Emacs can, in fact, be told to do these trivial merges itself; press $ to do so. Emacs then skips the diffs where one of the buffers is equal to its ancestor.

Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 14: Finding Differences Between Files

Previous HourNext Hour

Sections in this Hour: