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.
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.