5

I've tried to search for the answer but I cannot precisely define the terms without falling under wrong threads all the time.

What happened: Accidentally I've selected all the code inside a file.m and deleted it all. It became a full blank document. When I pressed Ctrl+Z to UNDO it, the xcode crashed.

The problem: When I reopened the xcode (after the crash) , the file was still all blank (It was autosaved seconds before the crash as a blank document) - losing all my code. I could not use UNDO to rescue me on this because it autosaved and crash.

What do I need: Is there a way to recover/revert my file to a previous state before this autosaving/crash?

Extra information: Source Control: I can't use it because the last "commit" was June 27.

Time Machine: Don't have external HD to use it. It is disabled.

Updated 1: I've pressed the button "discard last change" and the file.m reverted to the file saved June 27. So, one more problem: Lose all the months of work up until now.

Update 2: I've found the solution, and posted below. But I need to wait until tomorrow to accept it as answer.

Update 3: I've reedited the text to clarify my problem.

1 Answers1

15

Oh! I fix it. I've opened the file.m with TextEdit. Then I browse to: File > Revert To> Browse All Versions

It led me to a place with all saved versions of the file, where I could search with a timeline the exact moment I need.

enter image description here

I've find the version previous to the blank/crash moment, and copied the text, paste it at file.m on xcode( also saved, commit it to source control for safety) and everything is ok now. I could recover all my code again.

  • 2
    glad I could help. I know the feel, bro. haha – ゴスエン ヘンリ Oct 17 '14 at 07:22
  • 2
    You are a beautiful person. Thank you so much for posting this. – Reuben Tanner Oct 21 '14 at 21:52
  • 1
    This is awesome! This gives you more versions, better granularity than time machine backup! – Keith Knauber Sep 10 '15 at 22:12
  • This should be the standard answer for xcode recover unsaved file xcode crash recover unsaved file – Keith Knauber Sep 10 '15 at 22:12
  • This was my first post here and ppl was really not liking it at all in the beginning. After that I was really insecure to answer my own question and get banned or something haha :~~ I'm so glad this is helping a lot of people. :D – ゴスエン ヘンリ Sep 10 '15 at 23:01
  • Thank you thank you thank you!!! Clever trick to simply open in TextEdit. Saved me so much time after I accidentally redirected `cat source > ./command.py` instead of piping `cat source | ./command.py` to a script I was developing outside of version control. Pheww! – natevw Sep 01 '16 at 23:06