0

I just need to revert my project back to a previous Commit. I'm already doing Version Control using XCode's built-in tool (and git).

I have already seen this too : [How to switch entire XCode project to previous commit] but I have nothing to do with SourceTree or Schemes.

I have already tried to revert using SmatGit but XCode said it couldnt understand the resulting project's format.

I have tried many commands from here How to revert Git repository to a previous commit? and here How do I restore from a previous commit on Xcode 8?

I was working on the Tinder Clone from the Udemy Course, when i added the Facebook SDK, parse stopped letting my USer login. Now i want to delete all the additions for adding the FB SDK, but the methods I have tried provided have failed to help so far. Still working, but I hope someone can help.

nyxee
  • 2,773
  • 26
  • 22

3 Answers3

2

I never trust Xcode for these kind of operations. Would do

  1. Exit Xcode
  2. Take a command prompt and cd to checkout folder for workspace
  3. run either of these commands from command prompt

    a) git stash
    b) git reset --hard

    If you do the first, you can apply your changes again by git stash apply

thomas gotzsche
  • 367
  • 2
  • 7
1

"Compare File Versions to Revert Lines of Code Choose View > Version Editor > Show Comparison View to compare versions of files saved in a repository. "- Hackless How to restore previous version of code in Xcode

Mihir Thanekar
  • 508
  • 4
  • 8
  • don't know how to post here, failed : `#!/bin/sh # # restores an old version of xcodeproject from git repository # into folder $HOME/gitcopy # current directory must be the rootdir of the project # Xcode should not access the same project at this time # set -x PROJECT_ROOT=. COPY_DEST=$HOME/gitcopy if [ -e *.xcodeproj ] then git log echo "Which version ?" read x git checkout $x git checkout -b copyVersion cp -R $PROJECT_ROOT $COPY_DEST git stash git checkout master; else echo "No xcode project root folder"; fi` – nyxee Jun 26 '17 at 18:34
  • If the revision you want to revert to was the last save you can go to file> revert to saved in xcode. – Mihir Thanekar Jun 26 '17 at 19:02
0

this is the best try i have seen so far...

#!/bin/sh
#
#  restores an old version of xcodeproject from git repository
#  into folder  $HOME/gitcopy
#  current directory must be the rootdir of the project
#  Xcode should not access the same project at this time
#
set -x
PROJECT_ROOT=.
COPY_DEST=$HOME/gitcopy
if [ -e *.xcodeproj ]
then
    git log
    echo "Which version ?"
    read x
    git checkout $x
    git checkout -b copyVersion
    cp -R $PROJECT_ROOT $COPY_DEST
    git stash
    git checkout master;
else
    echo "No xcode project root folder";
fi 

it's from How to restore previous version of code in Xcode, but more files are getting lost in the process than necessary...

Ok.. that was the Ultimate Solution. The problem had been that XCode had created some files i had added only by reference, and were not added to the Project, so, i think git didn't know about them.

When i finally added the Missing (highlited in red) files manually from the project's old copy, everything stated working according to the commit of interest.

Thanks for the help.

You have to run the script, select the code for the commit you want, then the solution will be copied into ~/gitcopy directory. Open the Project in XCode and copy any missing files from a previous copy (or, make references) of the Project...

nyxee
  • 2,773
  • 26
  • 22
  • 1
    Wait I don't understand. Why couldn't you just use git revert ? – Mihir Thanekar Jun 26 '17 at 19:04
  • when I did that, XCode said it could no longer parse the project... but i will to have test this git extensively it seems. I think the problem was that i had started the project from samples, so, even before my initial commit, there wer commits in the project, and it looked like two different projects.. maybe thats what it means when ur working on open-source projects... – nyxee Jun 27 '17 at 11:48