4.5. Comparing Files

Problem

You need to see the differences between two files displayed graphically.

Solution

Select the files in a view and then select Compare With Each Other in the view’s context menu.

Discussion

One of the most common things professional developers need to do is to compare the contents of two files to see the changes made to each; the support in most operating systems for such operations is minimal.

To compare two files, highlight them in a view such as the Package Explorer and select Compare With Each Other in the view’s context menu. Eclipse will perform the comparison in an intelligent manner and display the results in a Compare Editor, as shown in Figure 4-10.

Comparing two files

Figure 4-10. Comparing two files

You even can edit the files, copying changes from one file to the other using the buttons in the Java Source Compare pane.

Tip

You can ignore comments and formatting changes when performing the comparisons: click the Ignore Whitespace option in the Compare Editor’s toolbar button (that’s the fourth button from the right in the main toolbar in Figure 4-10). This is useful when working with XML.

See Also

Recipe 4.6 on comparing files against local history; Recipe 4.7 on restoring elements and files from local history.

Get Eclipse Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.