29

Can someone explain how Eclipse's local history works?

I accidentally overwrote a file in a project but need to revert to an earlier version. Is there a chance that Eclipse has the older file cached somewhere?

6 Answers6

43

To complete CurtainDog's answer: from eclipse FAQ

Every time you modify a file in Eclipse, a copy of the old contents is kept in the local history. At any time, you can compare or replace a file with any older version from the history.
Although this is no replacement for a real code repository, it can help you out when you change or delete a file by accident.
Local history also has an advantage that it wasn’t really designed for: The history can also help you out when your workspace has a catastrophic problem or if you get disk errors that corrupt your workspace files.
As a last resort, you can manually browse the local history folder to find copies of the files you lost, which is a bit like using Google’s cache to browse Web pages that no longer exist.

Each file revision is stored in a separate file with a random file name inside the history folder. The path of the history folder inside your workspace is

.metadata/.plugins/org.eclipse.core.resources/.history/

You can use your operating system’s search tool to locate the files you are looking for.


Note, if your need to import your local history into a new workspace, you will need both:

  • .metadata/.plugins/org.eclipse.core.resources/.history
  • .metadata/.plugins/org.eclipse.core.resources/.project

to have a functional local history in that new workspace.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I don't find it in juno version. any idea? – Dejell Oct 23 '14 at 13:46
  • @Dejel strange: it is still described as using that path in http://wiki.eclipse.org/FAQ_Where_is_the_workspace_local_history_stored%3F. Maybe you could ask a separate question? – VonC Oct 23 '14 at 13:55
  • 1
    This helped silly me out when I accidentally did override and update on a file I wanted to keep causing the file to delete and then forgot the class name... As a tip for anyone browsing sorting by date modified allows you to find the most recent caches when trying to find the one to recover. – William Jarvis Nov 04 '15 at 14:02
  • Can you help? I upgraded my workspace folder from Eclipse Mars to 2020-09 and now, the local history is not working. The project is part of SVN. On a new workspace, it is working fine. – tarekahf Jan 13 '21 at 17:40
  • 1
    @tarekahf Not sure, I never upgrade my workspace, I always create separate workspace per Eclipse version, to avoid any surprise. – VonC Jan 13 '21 at 17:41
  • Oh, thanks. I just solved it. I have to increase the file size in the limits of the Local History section under Preferences. – tarekahf Jan 13 '21 at 17:51
22

Try right-clicking on the file in eclipse, and choose Replace With->Local History.

If there's history available, it'll show up as a list of edit times.

But more importantly, as pointed out in other answers, be sure to put your files in version control! SVN is pretty easy to set up (you don't need a server; it can just use the file system); use it even if you aren't sharing with others.

A tip: whenever you hear yourself say "yes!", check in all of your code. 10 minutes later, you'll be saying "how did I mess that up?"

Scott Stanchfield
  • 29,742
  • 9
  • 47
  • 65
  • 1
    Your tip is a very concise explanation of how/why to use version control for those who don't. I might have to steal that. – Frank Riccobono Jul 01 '14 at 22:07
  • 1
    I newer eclipse versions you can also use Replace With -> Previous from Local History, which is much faster when you know for sure you need just go back one change back. For example if you need to get back changes reverted accidentally. – Dcortez Sep 16 '14 at 16:16
  • Thanks, was really really helpful, much appreciated – Stephen Kennedy May 08 '17 at 10:09
8

If you have lost a full package structure due to accidental deletion or svn/cvs override, select the project> right click> Restore from local history => select the files.

chandima
  • 81
  • 1
  • 1
  • This works if the file has been deleted, but how massively rollback edits of many files from history? Currently the only method I found is to right click on each file to check if there are files in history! – Tobia May 28 '21 at 15:45
3

VonC's answer has all the information you need for finding the location of your code backups. I would simply add that if you are on a Mac or Linux, you can do something like this:

$ cd [WORKSPACE]/.metadata/.plugins/org.eclipse.core.resources/.history/
$ grep -rl "class Foo" . | xargs ls -lt

This will find all the versions of a file that contains a particular string (ie. "class Foo"), and sort them by date/time to easily find the most recent version.

6006604
  • 7,577
  • 1
  • 22
  • 30
2

You can use the link http://wiki.eclipse.org/FAQ_Where_is_the_workspace_local_history_stored%3F is very helpfull

Tomasz Waszczyk
  • 2,680
  • 5
  • 35
  • 73
0

Open the CVS view and you should see a filter for local history. You should then be able to right-click on the correct version and Get Contents or do a manual compare and merge. I'm not sure what the eclipse defaults are for keeping local history but there is a decent chance you'll be able to get your stuff back if you act quickly.

CurtainDog
  • 3,175
  • 21
  • 17