Save vs Commit in Xcode?

Hi all,

I noticed in Xcode that you can save files using the usual File then Save, or you can commit files using git source control.

I was just wondering what the difference is between using these and which would be the recommended way to save changes as I go, before I want to push to Github?

Github is all I have really used so far and I would love to know what my options within Xcode (locally) are.


*Also, if I do "Save" from File menu, does that save all files in project, or just the one currently selected?*

Answered by QuinceyMorris in 252783022

Save causes in-memory editing changes to be written back to their file(s) locally. In effect, this has nothing to do with source control — changes are changes, regardless of whether they've been written to disk yet. (However, until they're written to disk, the changes might not be visible to other SCM-related apps that you might use, such as the git command line tool.)


File -> Save saves the current file, which is the one in the currently active editing pane. You can hold down the Option key when choosing from the File menu to save all files that have changes. (The default key equivalents are Command-S and Command-Option-S.)


>> the recommended way to save changes as I go


As they say, "Save early, save often"! What you don't want is to make a series of changes, perhaps to multiple files, and lose your edits if Xcode crashes. You can always undo your changes, or use the file version browser to examine previous versions of your file(s). (Unfortunately, you can't get to the file version browser from Xcode, but you can with TextEdit — open a source file in TextEdit, and use File -> Revert to Saved -> Browse All Versions.)


>> before I want to push to Github


Most developers recommend making small commits fairly frequently, rather than waiting till you're ready to push and making one big commit. The idea with small commits is that it's easier to find a specific change, if you ever need to browse the change history in the repository. (I have a problem remembering to commit often, but in principle it's good advice.)


For those of us who have lost edit due to Xcode crashes or other similar reasons, we learn to save obsessively a few seconds after we make a change. The interval between commits is more likely to be minutes or hours. FWIW

Accepted Answer

Save causes in-memory editing changes to be written back to their file(s) locally. In effect, this has nothing to do with source control — changes are changes, regardless of whether they've been written to disk yet. (However, until they're written to disk, the changes might not be visible to other SCM-related apps that you might use, such as the git command line tool.)


File -> Save saves the current file, which is the one in the currently active editing pane. You can hold down the Option key when choosing from the File menu to save all files that have changes. (The default key equivalents are Command-S and Command-Option-S.)


>> the recommended way to save changes as I go


As they say, "Save early, save often"! What you don't want is to make a series of changes, perhaps to multiple files, and lose your edits if Xcode crashes. You can always undo your changes, or use the file version browser to examine previous versions of your file(s). (Unfortunately, you can't get to the file version browser from Xcode, but you can with TextEdit — open a source file in TextEdit, and use File -> Revert to Saved -> Browse All Versions.)


>> before I want to push to Github


Most developers recommend making small commits fairly frequently, rather than waiting till you're ready to push and making one big commit. The idea with small commits is that it's easier to find a specific change, if you ever need to browse the change history in the repository. (I have a problem remembering to commit often, but in principle it's good advice.)


For those of us who have lost edit due to Xcode crashes or other similar reasons, we learn to save obsessively a few seconds after we make a change. The interval between commits is more likely to be minutes or hours. FWIW

>...would love to know what my options within Xcode (locally) are.


I've been rescued many times by an external Time Machine volume while working w/Xcode over the years...backs up every hour and I don't have to remember to pull the trigger.

Thank you for such a detailed answer. When making these small commits, do you use Xcodes own version control and do Source Control -> Commit? Or do you commit elsewhere for backup?

I do the commits in Xcode, and push to a GitHub remote. The remote is my off-site backup, and (like KMT) Time Machine is my local backup.

Save vs Commit in Xcode?
 
 
Q