Compare and Merge with Eclipse

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:

Comparing Files and Folders with Classic CodeWarrior

Comparing Files and Folders with Classic CodeWarrior

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:

Eclipse menu to compare files with each other

Eclipse menu to compare files with each other

That brings up the following view, where I can see the differences between the two files, side by side:

Comparing two files

Comparing two files

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:

Select Common Ancestor

Select 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:

3-Way Compare View

3-Way Compare 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:

3-Way Compare with Ancestor

3-Way Compare with Ancestor

Compare With works not only with files, but as well with folders:

Directory Compare

Directory Compare

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:

Compare with Repository

Compare with 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:

Compare with Local History

Compare with Local History

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:

Compare Preferences

Compare Preferences

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’:

Drag & drop files into dummy project to compare external files

Drag & drop files into dummy project to compare external files

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 🙂

15 thoughts on “Compare and Merge with Eclipse

  1. Pingback: 5 Best Eclipse Plugins: #3 (System and Desktop Search) | MCU on Eclipse

  2. Pingback: Eclipse Local History & Quick Diff | MCU on Eclipse

  3. Pingback: Restore Deleted Files in Eclipse with Local History | MCU on Eclipse

  4. Pingback: Show it again! (How to re-enable hidden Dialogs in Eclipse) | MCU on Eclipse

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

    Like

    • Hi John,
      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 🙂

      Like

  6. Pingback: Compare External Files in Eclipse | MCU on Eclipse

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

    Like

    • 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 ?

      Like

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

      Like

      • Hi Greg,
        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.

        Erich

        Like

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.