Eclipse's local history...where are files saved?
Asked Answered
S

6

30

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?

Spoondrift answered 9/6, 2009 at 12:27 Comment(0)
S
44

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.

Stokeontrent answered 9/6, 2009 at 12:55 Comment(6)
I don't find it in juno version. any idea?Kettle
@Dejel strange: it is still described as using that path in wiki.eclipse.org/…. Maybe you could ask a separate question?Stokeontrent
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.Epistrophe
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.Hydromagnetics
@Hydromagnetics Not sure, I never upgrade my workspace, I always create separate workspace per Eclipse version, to avoid any surprise.Stokeontrent
Oh, thanks. I just solved it. I have to increase the file size in the limits of the Local History section under Preferences.Hydromagnetics
H
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?"

Heliostat answered 9/6, 2009 at 14:11 Comment(3)
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.Highup
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.Citric
Thanks, was really really helpful, much appreciatedChelseychelsie
F
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.

Fusil answered 23/11, 2010 at 2:4 Comment(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!Alumina
G
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.

Gristmill answered 31/10, 2018 at 14:49 Comment(0)
S
2

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

Shamble answered 15/10, 2013 at 14:54 Comment(0)
M
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.

Magazine answered 9/6, 2009 at 12:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.