RPB
RPB

Reputation: 16350

How do I compare two files using Eclipse? Is there any option provided by Eclipse?

How do I compare two files using Eclipse?

(Currently I am using WinMerge.)

Upvotes: 243

Views: 240528

Answers (8)

Rob M
Rob M

Reputation: 33

If you bind the Compare with other Resource command to a key via Window > Preferences > General > Keys (as described by the answer from bmaupin and barani-r), change the When: option to In Dialogs and Windows. It seems this will open the dialog even if you don't have a file selected, but if you do have a file selected/in focus, it'll be pre-filled as the first file in the comparison.

(I suggest an easy key bind to remember is a combo like Alt + "=".)

Upvotes: 0

randyj
randyj

Reputation: 1

If you have Beyond Compare installed, the ContextQuickie eclipse plugin has an option to enable it to be selected from the context menu displayed when you right-click a file.

Install from:

https://github.com/ContextQuickie/ContextQuickie/wiki/Installation

After install, activate Beyond Compare menu items via Window->Preferences->Context Quickie->check 'Enable Beyond Compare'.

Upvotes: 0

Barani r
Barani r

Reputation: 2367

Compare with Other Resource – The Easy Way using Eclipse (no additional plugin required)

To assign a keyboard shortcut to the feature, go to Window > Preferences > General > Keys, look for the command Compare with Other Resource and assign it to a keyboard shortcut of your liking. See How to manage keyboard shortcuts in Eclipse for more details on configuring shortcuts.

Tip: Alternatively, you could press Ctrl+3 (for Quick Access) and search for Compare with Other Resource. This way you don’t have to configure a shortcut but you’ll have to search for the command every time in Quick Access.

Once the shortcut is assigned, you need to select the source file from the Package Explorer, Project Explorer or Navigator. The easiest way to do this from an open editor is to assign a shortcut to instantly show the file in the Package Explorer or, if it’s not open, to open it quickly using the keyboard.

Select_File_In_Package_Explorer

Now press the keyboard shortcut you assigned to Compare with Other Resource and the following (non-modal) dialog should appear:

Compare With Each Other Dialog

Troubleshooting: If the dialog doesn’t appear, it’s probably because you haven’t selected a file in either the Package Explorer or another view that allows file selection. Make sure a file is selected and make sure you haven’t selected the class in the Package Explorer rather than the actual Java file.

Now you can select the second file in the Package Explorer and drag and drop it onto the dialog. Click OK and the comparison editor should display, comparing the two selected files.

Comparison Editor

Tip: See the post on using shortcuts for common SVN commands for tips on how to navigate the comparison editor with the keyboard.

Comparing External Files Using the Compare with Other Resource dialog, you can compare a workspace file with an external file or even compare two external files with each other.

Comparing a workspace file with an external file is easy: Once you’ve opened the dialog from a selected file, instead of dragging and dropping another workspace file, tick External File in the Right pane and then Browse to a file on your filesystem.

comparing external

To compare two external files, you have to start the dialog again from a selected workspace file (choose an arbitrary file). Once open, select External File in the Left pane and Browse to your file then do the same for the Right pane.

Please refer this page for more details: http://www.eclipseonetips.com/2013/09/19/compare-two-workspace-or-external-files-in-eclipse/

Upvotes: 4

andrew pate
andrew pate

Reputation: 4307

If your compairing javascript you might find it not displaying.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=509820

Here is a workround...

  • Window > Preferences > Compare/Patch > General Tab
  • Deselect checkbox next to "Open structure compare automatically"

Upvotes: 2

bmaupin
bmaupin

Reputation: 16015

If one or both of the files you wish to compare isn't in an Eclipse project:

  1. Open the Quick Access search box

    • Linux/Windows: Ctrl+3
    • Mac: ⌘+3
  2. Type compare and select Compare With Other Resource

  3. Select the files to compare → OK

You can also create a keyboard shortcut for Compare With Other Resource by going to WindowPreferencesGeneralKeys

Upvotes: 16

armyofda12mnkeys
armyofda12mnkeys

Reputation: 3472

Other than using the Navigator/Proj Explorer and choosing files and doing 'Compare With'->'Each other'... I prefer opening both files in Eclipse and using 'Compare With'->'Opened Editor'->(pick the opened tab)... You can get this feature via the AnyEdit eclipse plugin located here (you can use Install Software via Eclipse->Help->Install New Software screen): http://andrei.gmxhome.de/eclipse/

Upvotes: 6

Vikas Patidar
Vikas Patidar

Reputation: 43359

To compare two files in Eclipse, first select them in the Project Explorer / Package Explorer / Navigator with control-click. Now right-click on one of the files, and the following context menu will appear. Select Compare With / Each Other.

enter image description here

Upvotes: 389

Doon
Doon

Reputation: 20232

Just select all of the files you want to compare, then open the context menu (Right-Click on the file) and choose Compare With, Then select each other..

Upvotes: 43

Related Questions