Since Jitesh is currently writing an extremely interesting series of posts on diff and patch (1,2), I decided to pitch in with my contribution. Ediff is one of those things which make Emacs so much more than just an editor. It is an extremely convenient way of viewing differences in files / buffers / directories.. You get the point.
Following the teaching tradition I prefer, lets get our hands down and dirty, and figure out the theory along the way:
Fire up ediff mode for our two files.
The mini-buffer will ask you to enter the two files to compare (A and B). The order in which we enter the files does not matter, but tradition dictates that file A should be the original and file B should be the modified file.
Can you see the small blue window at the top? That is the ediff floating window. All ediff commands are processed (for lack of a better word) by this window. This window can be expanded to offer the quick help for ediff, which I believe is self-explanatory.
To point out the simple stuff, ‘v/V’ will scroll the two buffers (simultaneously) up and down, so you can read the orig and changed code. ‘n’ will take you directly to the next diff point, and the highlighting is super-cool, as you can see. So on and so forth, go read the quick help.
If you want to compare to directories of code, you use the command
In this case, all files / directories inside your directories are bunched into sessions.A powerful (and easy-to-understand) UI is provided for manipulating sessions. In this way, you can go through the differences file by file, disposing the session once you are done with it.
Points to note:
1) You can apply differences from one buffer to another region by region, i.e selectively apply a patch
2) You can merge two files into a third buffer.
3) Ediff understands version control systems, so you can compare two versions of the same file
4) Ediff indicates exact word differences. If the only differences in two regions are whitespace or line breaks, ediff will tell you so.
5) All of the above can be carried out on three files / buffers / directories! I’m not even going here till I get a complete hang of this!
So, that’s it folks. This is without doubt the easiest way of browsing code diffs that I know. Hope you find ediff as useful as I found it!
Note: This post is based on a one day study of Ediff, something I did because I was interested in the feature for a long time. This means, as always, I have barely scratched the surface. I’ll post more stuff if I come across something super-cool
Further InformationThe Ediff Manual