1

I have a python file named initialization.py. When trying to copy-paste contents into a blank file, I used ctrl + x to copy/cut, closed the original file, and accidentally used ctrl + x again in the blank document of my text editor, then proceeded to save the blank document with the same filename initialization.py. So when I use ctrl + v, I am pasting empty space rather than the code. Is there a way to retrieve the contents of the python file before it was overwritten?

In case it's relevant, I'm using macOS High Sierra 10.13.6 and my text editor is Atom 1.37.0.

EDIT:

I followed the steps posted in this answer, but now I'm not sure what to do next.

terminal screen-capture

3
  • 2
    Restore the file from Time Machine backup?
    – Kusalananda
    Commented May 29, 2019 at 11:05
  • 1
    So you did cut, save and close the original file? So no chance to undo? And the linked answer doesn't help you, because the file was not deleted, but the contents were overwritten. Different thing. With APFS version history, the data would have been saved to a different block, so you could have restored it. And you also don't have a clipboard extension? With this combination of suicidal actions I don't see a chance to recover your contents.
    – Philippos
    Commented May 29, 2019 at 13:41
  • 1
    A great lesson here is use git and make regular "micro" commits. You can always rebase or squash merge them together. Commented May 29, 2019 at 14:40

1 Answer 1

1

Mistakes like this is why I wrote a script to automatically backup all of the small text files on my machine every 10 minutes. (also useful if you want to view the previous version of a file)

What you're asking is a data recovery question now:

  1. Do NOT use the drive for anything else. If it's your main system drive, turn the computer off immediately.

  2. You can try using the TestDisk and the PhotoRec tool for Mac to recover your files. It will produce thousands of different files, all unlabelled.

  3. Search through these files for a unique text string you remember from the script. Hopefully it's still there. Good luck!

You must log in to answer this question.