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?
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.
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?"
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.
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.
You can use the link http://wiki.eclipse.org/FAQ_Where_is_the_workspace_local_history_stored%3F is very helpfull
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.
Related
I have just accidentally deleted one week of coding source files, and even testdisk does not restore them. Even executable jars gone... I use ubuntu. I dont want that happen ever again. How to sufficiently and efficiently make automatic backups (clones) of selected critical files to a different location e.g. home?
I use java, and eclipse as IDE, but this could be any file i work with. E.g. i select certain file, because i can accidentally delete it, so this lightweight backup tool would automatically update it in saved backup location according to saved changes. So if it is lost in working directory, as in my case, i can just take it from backup site on local machine. Pls help. I feel devastated...
cwatch might be a solution i am looking for, but it is too complicated.
p.s. i am aware of question Script to perform a local backup of files stored in Google drive
google services not ok for me.
The simplest solution would be to use GitHub or Bitbucket and to regularly push the changes you made to the online repository. You will benefit more from the usage of a version control software then from a local backup. You can use either of them for free.
Using Visual Studio Code Version 1.8.1 how do I restore a deleted file in the recycle bin?
It uses the normal trash bin of your system. So you can grab it our of there.
In Windows you find it in the explorer, in Linux it is as well in Konquerer / Nemo / ...
First go to Recycle Bin of your local machine.
Your VS code deleted files is there in Recycle Bin.
So, Right click on deleted files and select-> Restore option then your deleted files
will be automatically restored in your VS code.
If you just deleted the file, know that VSCode 1.52 (Dec. 2020) will support:
Undo file operations in Explorer
Explorer now supports Undo and Redo for all file operations: delete, rename, copy, move, new file and new folder.
Make sure the focus is in the Explorer and trigger the Undo or Redo commands and your last file operation will be undone or redone respectively.
Keep in mind that we have separate undo stacks for the editor and the explorer and we choose which one to undo based on focus.
Running on Ubuntu 18.04, with VS code 1.51.0
My deleted files from VS Code are located at:
~/.local/share/Trash/files
Every deleted file have a corresponding .trashinfo file which contains details about where the file is deleted from and deletion date and these are located at:
~/.local/share/Trash/info
More info here.
To search for your deleted files:
find ~/.local/share/Trash/files -name your_file_name
In case you deleted files form a mounted ntfs filesystem, they will be located at:
/path_to_mounted_fs/.Trash-$UID
You can get $UID by doing echo $UID in your terminal.
Hope my case helped!
Click in empty space of VS Code's explorer (it's where you see files listed vertically) and press undo Ctrl + z
It'll recover your permanently deleted files too.
VS Code is a lifesaver. ✌
I know the OP says Recycle Bin. What I do though is recreate the file, especially if it's a single file. And when in the file, I just press CMD+Z (I'm on a Mac) and I get my file back.
Recreate the file in the same directory from where it was
deleted.
CMD+Z inside of the newly created file.
I accidentally discarded changes in the Source Control in VS Code, I just needed to reopen this file and press Ctrl-Z few times, glad that VS Code saves your changes like that.
If you can't find your files in the Windows Recycle Bin as it happended to me
(debugger went rogue and deleted the project folder)
look in the %APPDATA%\Code\User\History\ subfolders sorted by date modified.
There I could retrieve my seemingly lost files.
who still facing the problem on linux
and didnt find it on trash
try this solution
https://github.com/Microsoft/vscode/issues/32078#issuecomment-434393058
find / -name "delete_file_name"
If you have permanently deleted files, on macOS, you can see the history (the last month I guess) in $HOME/Library/Application Support/Code/User/History/. You will have to find your file(s) by looking at each entries.json file in every subfolder and rename the last version of your file.
There is probably a similar way on windows and linux but I don't know the precise paths.
I tried most of the options above but none worked.
What worked for me was clicking and highlighting the folder where the file was deleted from in vscode. Then while it is selected, hit CTRL + Z.
This works on windows.
Hitting CTRL+Z without highlighting that folder didn't work.
Just look up the files you deleted, inside Recycle Bin. Right click on it and do restore as you do normally with other deleted files. It is similar as you do normally because VS code also uses normal trash of your system.
While pushing a repository to Github through Vs Studio code I deleted whole folder and they were not available in Recycle bin also. Here is how I recovered those files.
For Windows.
The method is to restore the previous version of the Drive in which the deleted file existed
I had deleted files from G: drive, the below images are self explanatory
Open properties menu of the drive
In properties go to previous versions tab,
where you can find the previously stored versions of that drive along with date at time of backup
use open or click on restore to get the previous version of that drive.
Note: Manipulations in the drive after restore point won't be available
I am not sure how I deleted a file in VS Code, and couldn't find it in recycle bin. Found the file using the History feature of File Explorer.
A month recovery can be done in visual studio code
1 Right click on file and
2 click Open Timeline and
3 select file from timeline
4 the last time file saved by you
5 and your last change of the file is recovered
NOTE : Not only last but all the previously saved check points can be recoverd from vs code
For Mac, try to search some parts of the code in the deleted file in the following path:
~/Library/Application Support/Code
I found a deleted file in this folder
~/Library/Application Support/Code/Backups
Yes, I know this question is about VS Code but I think I can help someone.
I permanently deleted a file, and I tried all the tips wrote here with no success. So I had to recover the file from OS Linux following this
grep -a -C 500 -F 'Unique string in text file' /dev/sda
It was asked above if there is a way to disable the ability to delete a file you created with an undo (#rochasdv).
There is a new setting to disable undo for file operations:
Explorer: Enable Undo default is warn, confirmation dialog
You can also set it to disable so that your files/folders will not participate in undo operations.
You can alo set it to allow - the pre-new setting situation.
Currently, this new setting is in the Insiders Build v1.64 so it may be in Stable early February, 2022.
I am working on Windows with a Ubuntu WSL. I permanently deleted a file by mistake and was not able to restore it from the recycle bin nor by doing anything else.
I however, was able to get my files content by going to "Timeline" and see all my previous modification (it will open a comparison window).
Hope it will help somebody.
I had the case that I, accidentally, deleted a committed file (git) with a ton of additional uncommitted changes, and I could not get it back. (two days of work! yeah, I know, commit early commit often, I know ...)
I had no linux trash can setup on my docker instance and was developing via remote ssh.
I tried to recreate the file and then do a ctrl+Z to recapture the changes as some suggested here. This did not work for me.
So after a struggle over an hour I finally gave up and thought the changes to the file were lost.
However,
I discarded the changes in git, that the file was deleted.
And THEN I retried ctrl+Z and boom all the changes previously came back
magically!
I was a happy camper!
If your local directory has git initialized and you have not committed the changes that include the delete, you can use git checkout -f to throw away local changes.
If you completely delete any of the components in angular using visual code, you can restore it
Go to Recycle Bin and restore the deleted component that will be restored in the project.
In eclipse, you can right click in a file and then select Team / Show local history. This shows your local saves and is pretty useful.
Now, I made some changes to a file. I am 100% certain I made them. But they have disappeared. Overwritten by someone else I guess. But when I check my local history I can't see my file changes.
My question is:
Does Eclipse always update the local file history for every save? How reliable is it?
Note: I appreciate people are thinking how can someone else overwrite your files. I am working in a force.com project. When you make changes to a file they are push to a central server. There is source control per se. It is like everyone working with a shared folder.
It depends. Each Eclipse plugin dealing with workspace artifacts can optionally set a flag for local history in its API calls to the workspace resource management when deleting or changing files. If the flag is set, changed files surely get copied into local history. But every plugin can set this flag different.
So even if you might have an editor plugin which always uses local history when saving the edited file, another plugin might delete/modify the file without using local history and therefore interfere.
Summary: Local history is not a reliable way to go back to previously saved versions of a file.
If anyone else runs into this issue, check to make sure you didn't accidentally edit a file in a build or target directory. For instance if you are working on a jsp page and make edits, swear you changed it but they are no longer there in the editor or the local history when you open the file, check to make sure you weren't editing the built version by accident.
This sometimes happens if you are quick to use ctrl-shift-R shortcut to open resources. To avoid this, you can set your build or target folder to derived by right clicking on the folder and checking the derived checkbox. This will prevent the resource from showing in the Open Resource view which could save you headaches later.
To get the code back, I opened the target version and used undo to get to the edited version.
After a lot of experiments, my team concluded that working with hijacked files in a snapshot view is the most efficient way to use ClearCase version control. The problem is that after each update/merge operation it leaves a lot of garbage in the directory. These are files with extensions like .keep.9 or .contrib.16.
These garbage makes it difficult to see if some file is private and we have forgot to add it to the repository. Is it possible to automatically erase these files?
It looks like you can't configure some files to be ignored, a basic feature of every other version control system.
.keep.x files are generated by a cleartool update -keep.
One solution would be to use a cleartool update -overwrite, which would not generate .keep.x files.
.contrib.x are generate by cleartool merge. See "Explanation of .contrib files left for every version just delivered in UCM".
The general idea though is to find and remove automatically all .keep.x and .contrib.x files after each update/merge, through a shell command.
For instance in Windows:
del /s *.contrib*
# or
for /R %i IN (*.contrib) do del %i
Note that you have other temporary files you need to pay attention to: see About the temporary files created by ClearCase.
I sometimes use the feature 'Reconcile Offline Work...' found in Perforce's P4V IDE to sync up any files that I have been working on while disconnected from the P4 depot. It launches another window that performs a 'Folder Diff'.
I have files I never want to check in to source control (like ones found in bin folder such as DLLs, code generated output, etc.) Is there a way to filter those files/folders out from appearing as "new" that might be added. They tend to clutter up the list of files that I am actually interested in. Does P4 have the equivalent of Subversion's 'ignore file' feature?
As of version 2012.1, Perforce supports the P4IGNORE environment variable. I updated my answer to this question about ignoring directories with an explanation of how it works. Then I noticed this answer, which is now superfluous I guess.
Assuming you have a client named "CLIENT", a directory named "foo" (located at your project root), and you wish to ignore all .dll files in that directory tree, you can add the following lines to your workspace view to accomplish this:
-//depot/foo/*.dll //CLIENT/foo/*.dll
-//depot/foo/.../*.dll //CLIENT/foo/.../*.dll
The first line removes them from the directory "foo" and the second line removes them from all sub directories. Now, when you 'Reconcile Offline Work...', all the .dll files will be moved into "Excluded Files" folders at the bottom of the folder diff display. They will be out of your way, but can still view and manipulate them if you really need to.
You can also do it another way, which will reduce your "Excluded Files" folder to just one, but you won't be able to manipulate any of the files it contains because the path will be corrupt (but if you just want them out of your way, it doesn't matter).
-//depot/foo.../*.dll //CLIENT/foo.../*.dll
Yes, But.
Perforce version 2012.1 added a feature known as p4ignore, inspired by Git. However the Perforce developers made a change to the behaviour, without justification, that happens to make the feature a lot less useful.
Whilst Git takes rules from all .gitignore files, Perforce doesn't know where to look until you specify a filename in an environment variable P4IGNORE. This freedom is a curse. You can't hack on two repositories that use different names for their ignore files.
Also, Perforce's ignore feature doesn't work out the box. You can set it up easily enough for yourself, but others don't benefit unless they explicitly opt-in. A contributor who hasn't may accidentally commit unwelcome files (eg. a bin folder created by a build script).
Git's ignore feature is great because it works out the box. If the .gitignore files are added to the repository (everyone does this), they'll work out the box for everyone. No-one will accidentally publish their private key.
Amusingly, the Perforce docs shows '.p4ignore' as an example ignore rule, which is backwards! If the rules are useful, they should be shared as part of the repository.
Perforce could still make good on the feature. Choose a convention for the file names, say p4ignore.txt, so the feature works out the box. Drop the P4IGNORE environment variable, it's counterproductive. Edit the docs, to encourage developers to share useful rules. Let users write personal rules in a file in their home folder, as Git does.
If you know anyone at Perforce, please email them this post.
This works as of Perforce 2013.1, the new P4IGNORE mechanism was first added in release, 2012.1, described on the Perforce blog here:
https://www.perforce.com/blog/new-20121-p4ignore
As it's currently described, you set an environment variable "P4IGNORE" to a filename which contains a list of the files to ignore.
So you can check it out to see how you like it.
If you want a solution that will apply to all work-spaces without needing to be copied around, you (or your sysadmin) can refuse submission of those file-types through using lines like the below in the p4 protect table:
write user * * -//.../*.suo
write user * * -//.../*.obj
write user * * -//.../*.ccscc
I remember doing this before, but I don't have the necessary permissions to test this here. Check out Perforce's Sysadmin guide and try it out
Perforce Streams makes ignoring files much easier, as of version 2011.1. According to the documentation, you can ignore certain extensions or certain paths in your directory.
From p4 help stream
Ignored: Optional; a list of file or directory names to be ignored in
client views. For example:
/tmp # ignores files named 'tmp'
/tmp/... # ignores dirs named 'tmp'
.tmp # ignores file names ending in '.tmp'
Lines in the Ignored field may appear in any order. Ignored
names are inherited by child stream client views.
This essentially does what #raven's answer specifies, but is done easier with streams, as it automatically propagates to every work-space using that stream. It also applies to any streams inheriting from the stream in which you specify the ignore types.
You can edit the stream via p4 stream //stream_depot/stream_name or right-clicking the stream in p4v's stream view.
And as #svec noted, the ability to specify ignore files per workspace is coming soon, and is in fact in P4 2012.1 beta.
Will's suggestion of using .p4ignore only seems to work with the WebSphere Studio (P4WSAD) plugin. I just tried it on my local windows box and any files and directories that I listed were not ignored.
Raven's suggestion of modifying your client spec is the correct way under Perforce. Proper organization of your code/data/executables and generated output files will make the process of excluding files from being checked in much easier.
As a more draconian approach, you can always write a submit trigger which will reject submission of change-lists if they contain a certain file or files with a certain extension, etc.
HISTORICAL ANSWER - no longer correct. At the time this was written originally it was true;
You can not write and check in a file that the server will use to make ignore rules; general glob or regexp file pattern ignore in perforce.
Other answers have global server configurations that are global (and not per folder).
The other answers show things that might work for you, if you want one line in your view per folder times number of extensions you want to ignore in that single folder, or that provide this capability in WebSphere Studio plugins only, or provide capability for server administrators, but not available to users.
In short, I find Perforce really weak in this area. While I appreciate that those who use the Eclipse Plugin can use .p4ignore, and I think that's great, it leaves those of us that don't, out in the dark.
UPDATE: See accepted answer for new P4IGNORE capability added mid-2012.
I have found it easiest to reconcile offline work using a BASH script like this one:
#!/bin/bash
# reconcile P4 offline work, assuming P4CLIENT is set
if [ -z "$P4CLIENT" ] ; then echo "P4CLIENT is not set"; exit 1; fi
unset PWD # confuses P4 on Windows/CYGWIN
# delete filew that are no longer present
p4 diff -sd ... | p4 -x - delete
# checkout files that have been changed.
# I don't run this step. Instead I just checkout everything,
# then revert unchanged files before committing.
p4 diff -se ... | pr -x - edit
# Add new files, ignoring subversion info, EMACS backups, log files
# Filter output to see only added files and real errors
find . -type f \
| grep -v -E '(\.svn)|(/build.*/)|(/\.settings)|~|#|(\.log)' \
| p4 -x - add \
| grep -v -E '(currently opened for add)|(existing file)|(already opened for edit)'
I adapted this from this Perforce Knowledge Base article.
I'm looking for a .p4ignore like solution as well (and not one tied to a particular IDE). Thus far, the closest thing I've found is p4delta. It sounds like it will do exactly what the original poster was asking, albeit through another layer of indirection.
http://p4delta.sourceforge.net
Unfortunately, while this does seem to produce the proper list of files, I can't get "p4delta --execute" to work ("Can't modify a frozen string") and the project has not been updated in year. Perhaps others will have better luck.
If you are using the Eclipse Perforce plugin, then the plugin documentation lists several ways to ignore files.