This is daily software engineering work: I need to compare two or more files to see their differences. And of course to merge the differences. There are many external tools available for diff/compare/merge, with WinDiff and KDiff3 just two I’m using. How to do the same with eclipse and MCU10?
‘Classic’ (non-eclipse) CodeWarrior has a nice compare feature built in:
I really love that feature in classic CodeWarrior. With the move of CodeWarrior to Eclipse, I feared that I will greatly miss that feature. Well, I was wrong. Eclipse can do the same, and even more and better!
In Eclipse, simply select two files (with using CTRL and the mouse) and select the context menu Compare With > Each Other:
That brings up the following view, where I can see the differences between the two files, side by side:
It comes with buttons to apply changes from left to right or from right to left: it has navigation buttons to move to the next and previous change, and on the side I have a visual indicator where all the other differences are.
But I cannot only compare two files, I can do this with three files too :-). I select three files and use the menu Compare With > Each Other. A dialog pops up asking me to Select the Common Ancestor:
The common ancestor is the base file with which the two other files compare with. Then this gives me a three-way comparison view:
Additionally there is another feature in the eclipse compare view: it does not only show the file, but as well the structure of the source file in an Outline View (see CodeWarrior Tool Tip #4: The Outline View).
Using the 3-Way offers two additional toolbar buttons: you can show or hide the ancestor file, or you can switch back to a two-way compare view:
Compare With works not only with files, but as well with folders:
Here I can find with the ‘+’ and ‘-‘ icon decorators, which files/folders are missing on either side of the compare. And clicking on a file compares the two with each other. And if I want to ignore white space characters, then there is a context menu too.
I’m using both CVS and SVN for version control: Instead comparing with a local file on my disk, I can compare it against a version in the repository:
And if I’m not using a version control system: I have Compare With > Local History… available. This gives me the History View for my file:
Double clicking on a line item in the History View compares that version with my current/local version. And here again I can select different lines in the History View as well and do a Compare With to compare arbitrary versions of my file.
What if I don’t like the look & feel of the Compare view? There are settings to change using the Window > Preferences menu:
And what if I don’t like that diff/merge/compare view? What if I want to use an external diff utility? Then I can use the External Diff plugin and set up to use my favorite diff/compare and merge utility.
But so far the eclipse built-in is my favorite one. At least for everything I deal with inside my workspace. I say ‘inside’, because there is one thing not supported directly in eclipse: to compare anything outside your workspace. But there is solution: In my workspace I have a ‘dummy’ project folder. If I want to compare files outside my normal project, I drag&drop the files or folders into that dummy project folder. Asked about how to handle the files, I say ‘Link to files and folders’:
Now I have them accessible in the workspace and can diff, compare and merge as usual. Once I have finished the compare and merge and do not need the links any more, I can remove it from my dummy project. With this, I can compare any files within Eclipse and MCU10.
Happy Comparing 🙂
Pingback: 5 Best Eclipse Plugins: #3 (System and Desktop Search) | MCU on Eclipse
Pingback: Eclipse Local History & Quick Diff | MCU on Eclipse
Nice tip about using a dummy folder to compare with external files – thanks!
Pingback: Restore Deleted Files in Eclipse with Local History | MCU on Eclipse
Pingback: Show it again! (How to re-enable hidden Dialogs in Eclipse) | MCU on Eclipse
We are a group of volunteers and starting a new scheme in our community.
Your web site provided us with valuable info to work on.
You’ve done an impressive job and our whole community will be grateful to you.
You’ve got amazing thing on this site.
Very nice and informative tutorial! Thanks for that.
But why do you work around with external files comparison instead of the built in feature “Compare with Other Resource” (Ctrl + 3 and search for that in Eclipse) as described here:
thanks for that link and tip, I was not aware of it. I believe that function was not present at the time I wrote that article, but I see that it is present in my Eclipse Juno and Kepler 🙂
Pingback: Compare External Files in Eclipse | MCU on Eclipse
First of all a big thanks for the detailed tutorial.
Also, I tried to install the External diff plugin from he link above but it came as a zip file and I’m facing issues installing it. Can you provide instructions, if possible, on how to install or point to a resource. Thanks in advance.
in that zip file, there is a ReleaseNotes.txt with installation instructions.
Sai, I am having the same trouble with the Ext Diff plugin – it does not show up after eclipse restart and can’t seem to be installed as new software via the Help selection. Have you discovered the resolution ?
The release notes were followed. Following them absolutely strictly, one finds that the folder that is moved into the Eclipse plugin folder itself contains a zip file with valuable files. Assuming it should be manually unzipped before (or after) the move, this becomes a non-strict application of the release notes file. Also, the release notes state “When you unzip the downloaded file, there will be a “plugin” directory. Go into the “plugin” directory “. Actually, that directory’s name is “plugins”. Bottom line is that all combinations of strict and non strict application of the release notes fail to provide access to the tool.
I don’t have used that external diff tool for about two years (I think), as I’m very happy with the Eclipse internal one.
Given the date of 2006 for that external diff plugin, I’m not much surprised that it will not work in latest Eclipse versions.
I’m sorry, but I don’t have any further advise about how to use it for commit compares: I’m mostly using eGit only for small things and using external Git clients for the heavy lifting.