I worked long hours on my project, and it was working well. But after a series of edits, somehow the application was not working the way it should. What did I change to break my code? Usually I smile, because I have things in a version control system. But: not this time (I should know better!). Luckily there are some ways to find out what has been changed: with the Local History and Quick Diff.
Local History
Even if not using a version control system, Eclipse has a local history built-in. To compare and diff with the history, I use the menu
This opens the History View which offers compare and merge (see Compare and Merge in Eclipse):
The number of entries (and size) of the local history is configured in the following workspace setting (menu Window > Preferences > General > Workspace > Local History):
Note: keeping a long history might slow down Eclipse, especially at workspace closure time (see CodeWarrior Tool Tip #3). So better not to keep too much of history.
Quick Diff
The Local History is nice, but there is even a faster way: Quick Diff!
Quick Diff can be enabled (if not already done) in the workspace settings (menu Window > Preferences > General > Editors > Text Editors > Quick Diff):
In the settings I can change the colors, and as well what to use as reference ((Version on Disk, Latest CVS Version or Pristine SVN Copy).
Note: There seems to be a problem (oversight?) in Eclipse (at least 3.6) with using ‘Version on Disk’: With saving a file the Quick Diff markers are gone too :-(. But it works as expected with the SVN settings. Another good reason to use SVN :-).
There is a general option to enable Quick Diff, and I have enabled as well the ‘Show differences in overview ruler’.
What it does: it shows the differences in the left editor area (where usually the line numbers are):
The colors are as configured in the Quick Diff preferences shown earlier.
If I move the mouse over the marker, a pop-up window shows up:
The first character in the pop up indicates what has changed:
- >: changed line
- +: inserted line
- -: deleted line
Note the ‘Press ‘F2′ for focus’: That way I copy and restore my earlier version. Quick is simple and fast and gives me an immediate access to the earlier version.
Happy Quick Diffing 🙂
Pingback: Eclipse Local History & Quick Diff | MCU on Eclipse | Laughing
To restore earlier version of code you could simply use context menu (click on “the left editor area” with the line numbers). There are different options: “Revert line\block”, “Restore deleted lines” etc.
LikeLike
That’s a very useful hint and addition to the tips!
LikeLike
Pingback: Eclipse Workspace Tips | MCU on Eclipse
Pingback: Restore Deleted Files in Eclipse with Local History | MCU on Eclipse