I accidentally closed my Xcode application. How do I undo any changes? - xcode

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.

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:
Quit Xcode.
Open the file you wish to bring back your lost changes to using TextEdit.
Go to File > Revert To > Browse All Versions...
Scroll through the available versions. Hopefully you will have many available to choose from.
Select a version and hit Restore.
Follow 2-5 for all necessary files.
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).

Related

Xcode source control won't commit

Problem:
When I hit "Commit..." under the Source Control menu in Xcode, the window comes up blank and I get a colorful pinwheel that doesn't stop spinning, so I have to force quit Xcode.
Details:
It's not a problem with Xcode in general because I can still commit other projects.
The version editor still works (I can still see previous commits I've made).
I've let the pinwheel run for over an hour, and still nothing happens.
I was able to commit this project up until a couple months ago. Since then, I added a few files to it, edited it a bit, updated Xcode if I remember right, and updated macOS.
Some of the files I added came from other projects.
I've tried removing some of the files I added and then committing, but that didn't work so I added them back.
I've tried cleaning the project, restarting Xcode, and restarting my mac.
I don't know much about source control, but I don't have anything fancy set up with a team or anything, it's just a local repository.
I've tried suggestions to delete various things inside the .xcodeproj file, to no avail.
I have Xcode 9.4.1
Any ideas?
If you have added big files (larger than 100mb) then sometimes Xcode has trouble with them. Try unstaging your commits and then committing them again. Finally try reverting back to the most recent version of your project and working from there.
I had the same problem. Sometimes selecting "Fetch and refresh status" works. The next time you go to commit the files will show up.
I found that rebooting my computer fixed the problem.

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)?
What happens when I “save” in Xcode IDE?
When you hit "Save" the changes you've made are saved to disk. XCode doesn't do this automatically. If it crashes you may lose all your code written after the last time it was saved to disk. But XCode saves the changes to disk even without hitting "Save" button in some cases.
Xcode automatically saves changes to source, project, and workspace
files as you work. This feature requires no configuration, because
Xcode continuously tracks your changes and saves them in memory. Xcode
then writes these changes to disk whenever you:
Build and run your app
Commit files to a source code repository
Close the project
Quit Xcode
https://developer.apple.com/library/archive/documentation/ToolsLanguages/Conceptual/Xcode_Overview/UsingFileSaving.html
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:
Then be sure to commit frequently. Xcode has a built in Git GUI, so that makes it easier:
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:
Open the 'Terminal' app
cd to the directory with the project
Run git log
Find the commit before you ruined everything
Copy the commit hash
Type q to exit the log
Run git reset --hard <THE-HASH-YOU-COPIED>
That should do it for you.
When creating a project check 'create git repository on my mac'.
Then commit changes when you're finished with one minor part and give the commit a comment so you know when looking into the history what changes you have done (quick overview).
With git you can quickly revert changes and go back to certain revisions like you can do in TimeMachine.
Further information are available at git's webpage.

Xcode 5.1: any way to suppress Revert/"Keep Xcode Version" dialog

As of Xcode 5.1, when I change the project out from under Xcode (in my case, most commonly, by checking out another git commit), it throws up an annoying dialog, even when not active:
Worse, I'm using Spaces (or Mission Control... whatever the hell it's called now), and the dialog gets separated from Xcode and lost, and yet it's modal and keeps Xcode from accepting input. Sometimes I find it, or it pops up in the Xcode space. Sometimes this requires force-quit on Xcode to get control back.
Short of quitting Xcode every time I change commits, is there any way to end this madness?
I chose revert to disk because the "disk" is the new code which I just pulled down from my repo. "keep xcode" is the code that was sitting there before I chose to change branches or pull rebase.
Just close the project that you're going to make the change on before you make the change. I always close projects before I check out a different commit or branch, and never have this issue. It's safer to do it that way, too.
I don't think there's any way to just suppress it altogether, and if you did, you would have to choose a default behavior for it, which wouldn't necessarily always bet he same. So it would be a bad idea for Apple to give you an option of not showing it.

xcode does not show files in the commit window

I have checked out a copy of a SVN project, I have modified some files and want to commit the changes. If I go to File > Source Control > Commit. I see an empty list and a button saying "Commit X files". I expected a list of the modified files.
Now, I use the command line tool (svn ...). But I want to bring back the Xcode commit window.
How may I fix it?
BTW. I'm using Xcode 4.6.1
That is a very very strange screen shot. Sometimes Xcode's svn integration can be a bit strange. If I were you I would just cancel out of the strange empty dialog and use svn at the command-line in Terminal instead.
In file > preferences there is a source control section. You probably have the check box checked to update the source control automatically. So, because it is already updating the source control, it doesn't let you do it.
So you can uncheck that box to make it not automatic, then change something in your project and try to commit the changes. You will probably see some files now.

Make Xcode 4 stop auto staging with git

I hate it that whenever I make a change in Xcode 4 it automatically does a "Git add" command. Is there a way to make this stop?
What I do is perform all my git interaction through the command line. Since I can't get Xcode to ignore the fact that my project is under git control, and since therefore I can't get Xcode to stop doing git add for every new file I create, when I get to the command line the first thing I do is git reset to reset the index. This undoes all the annoying git add stuff that Xcode did automatically. Now I'm in charge of what goes into the index and so I get to form my own commits the way I want.
For Xcode 6 this is not an issue anymore. Visit Preferences -> Source Control tab and turn off 'Add and remove files automatically' checkbox
No. Xcode 4's git integration is "broken" in that they tried to present a uniform interface to source control regardless of whether the back-end is git or svn. That means they're supporting only the lowest common denominator of functionality. As a result, use of the index (the "staging area") is out. It always does auto-adds no matter whether you want it to or not.
EDIT: Actually, I don't think it auto-adds. I think it always does commit -a. Looking at git status on the command line shows me many new and modified files that are NOT staged. But I'm sure if I committed with Xcode they'd all end up in that commit.
For me, the solution was this one https://stackoverflow.com/a/6378745/1078859
TL;DR; remove the repository from xcode's organizer
While the question title says XCode 4 this question appears at the top for many search results related to this issue even in newer versions of XCode. Here is an answer that addresses newer versions of XCode. In XCode 6 you can turn off version control by going to XCode --> Preferences --> Source Control Tab and uncheck Enable Source Control.

Resources