1

I was testing out some new swift code. I knew that if I made any mistake I could simply revert back to my old code by pressing Command+Z.

But I accidentally closed my Xcode Editor while writing new code.

How would I undo the new changes and go back to my old original code? I did not make use of github for this.

lloydpick
  • 1,638
  • 1
  • 18
  • 24
J Duh
  • 161
  • 1
  • 11
  • 1
    You can't. That's what version control is for. – LinusGeffarth Apr 10 '18 at 13:18
  • 1
    You don't need github - just use your local git repository, or if you didn't bother to set that up then maybe go to your last Time Machine backup, which will be no more than 1 hour old ? – Paul R Apr 10 '18 at 13:19
  • Possible duplicate of [How to undo xcode discard all changes if not committed](https://stackoverflow.com/questions/25308554/how-to-undo-xcode-discard-all-changes-if-not-committed) – LinusGeffarth Apr 10 '18 at 13:36

1 Answers1

9

There might be a chance you can view the file's old history. Check out George Marmaridis' answer

Here is what he says:


You might not be out of luck. Although Git can't help you, Finder may be able to come to the rescue!

If you have not turned off the Versions feature (which by default is turned on and you need a Terminal command to disable), then do the following:

  1. Quit Xcode.
  2. Open the file you wish to bring back your lost changes to using TextEdit.
  3. Go to File > Revert To > Browse All Versions...
  4. Scroll through the available versions. Hopefully you will have many available to choose from.
  5. Select a version and hit Restore.
  6. Follow 2-5 for all necessary files.
  7. Launch Xcode. You should now see the M next to these files in Project Navigator indicating they include uncommited changes (the changes you previously discarded).
LinusGeffarth
  • 27,197
  • 29
  • 120
  • 174