Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore previous version of code in Xcode

I'm working on an Objective C project in Xcode and need to restore to a previous version that was committed in source control. How do I do that? I can find information on how to commit and push but no information on how to restore to an old version.

like image 519
Victor Engel Avatar asked Jan 12 '13 22:01

Victor Engel


People also ask

How do I see code history in Xcode?

Select the file for which you want to see the commit history. Then go to View > Version Editor > Show Version Editor (or just select the Comparison view from the top-right toolbar icon - same place as the Blame view). Clicking on the commit label below the editor will reveal the history including dates.


2 Answers

You cannot revert the entire project at once in Xcode, but you could do it from the terminal; just cd into the folder of your project and type git log to find the hash you're looking for, then do git checkout [hash].

like image 192
mlstudent Avatar answered Oct 20 '22 13:10

mlstudent


Quote from Apple's documentation at https://developer.apple.com/library/ios/documentation/ToolsLanguages/Conceptual/Xcode_Overview/Save_and_Revert_Changes_to_Files/ManageChanges.html

"Compare File Versions to Revert Lines of Code Choose View > Version Editor > Show Comparison View to compare versions of files saved in a repository. Use the jump bars to choose file versions based on their position within a repository. Each jump bar controls the selection for the content pane above it. To display a version, browse through the hierarchy to find it, then click to choose it. Shaded areas indicate changes between versions." "You can use the version timeline to choose file versions based on their chronological order. Click the timeline viewer icon (../art/TimeLineIcon_2x.png) in the center column to display the timeline between the two editing panes. Move the pointer up or down through the timeline to browse the available versions. When you find the version you want, click the left or right indicator triangle to display that version in the corresponding editor pane. You can edit the current working copy of the file in the version editor. If you want to revert changes between versions, you can copy code from an older version and paste it into the current version."

The last line reveals the key: copy-and-paste.

like image 40
Hackless Avatar answered Oct 20 '22 14:10

Hackless