Search code examples
xcodexcode8autosave

What happens when I "save" in Xcode IDE


I'm just starting to learn Swift using the Apple Xcode IDE. I made a little test iOS app and was trying various things when I inadvertently deleted my main code file (ViewController.swift). "No problem", I thought, as I had hit "Save" just a couple of minutes before. I exited out, then came back in, but it appeared to have autosaved.

I don't really care about this test file, but am wondering what is the proper way to save a project before trying something out (or before inadvertently pulling a bonehead move)?


Solution

  • Use Git. If you don't know what it is, look into it. In the mean time, here is a tutorial or two.

    To use it in Xcode, when you create a project, be sure to create a git repo:

    enter image description here

    Then be sure to commit frequently. Xcode has a built in Git GUI, so that makes it easier:

    enter image description here

    Then if you do anything that you shouldn't have you can either discard all changes (see the above screen shot, or if that can't help you, you can:

    1. Open the 'Terminal' app
    2. cd to the directory with the project
    3. Run git log
    4. Find the commit before you ruined everything
    5. Copy the commit hash
    6. Type q to exit the log
    7. Run git reset --hard <THE-HASH-YOU-COPIED>

    That should do it for you.