Deleted GIT repo. Revert local source.

I had a GIT repo where I pushed all my local commits, just for a backup. I deleted the git repo and now I need to revert my entire project to a previous version of the app (edit - using local commits). How do I do this? For saftey, I downloaded the project from GIT before deleting it.


Neerav

Replies

I checked in the version editor, all the commits are in their place. Instead of reverting to a previous commit, what I want to do now is make a branch from one of the previous comits and start my new work on another branch. This way I can have the option to merge two branches.


Please let me know how I can achieve this?

Assuming you're using Xcode 9, you can branch off a commit from Xcode's source control navigator. Select a branch from the source control navigator to see the commits from that branch. Select the commit where you want to branch, right-click, and choose Branch from. You can find more detailed information and screenshots in the article at the following link:


h ttp://meandmark.com/blog/2018/03/going-back-to-a-previous-git-commit-in-xcode/


Remove the space between the H and the T to get the link to work. I would supply a clickable link, but Apple holds replies with clickable links in moderation. It can take days for a reply to get out of moderation.

The blog post you linked says there is no way to roll back from a commit. Lets say I have a commit which i give a version no 1.1 and then I commit 1.2 and then 1.3 for 3 different features in the app. But I no longer want the features I put in 1.2 but want to keep those in 1.1 and 1.3, what do i do?

The blog post says there's no way to roll back to an earlier commit FROM XCODE. Xcode doesn't have support for everything you can do with git. You can go back to an earlier commit from the command line or from a git GUI tool like Sourcetree.


Rolling back to an earlier commit isn't going to solve your issue of discarding the 1.2 code but keeping the 1.3 code. If you roll back to version 1.3, you have the unwanted 1.2 code. If you roll back to version 1.1, you lose the 1.3 code you want.


I don't know any easy way to remove the unwanted 1.2 code while keeping the 1.3 code. You have two options.


Option 1: Branch off version 1.3 and remove the 1.2 code. Sourcetree lets you select a commit and click a Reverse hunk button to remove code, but it works better the closer the commit is to the most recent commit. You will probably have to remove a lot of the 1.2 code yourself.


Option 2: Branch off version 1.1 and add the 1.3 code.


I recommend Option 1 because it keeps the 1.2 code in your commit history in case you need it in the future. But if it's significantly more work to remove the 1.2 code than to add the 1.3 code, you can go with Option 1.

In option 2, won't the changes of 1.2 be a part of 1.3?


Also, I branched out from a version of my choice and now I want to set it as a current branch, but Source Control meny doesnt show the option as shown in this stackoverflow thread...

h ttps://stackoverflow.com/questions/44396681/switching-branch-on-xcode-9


Neerav


Edit: I did a 'check out' on the branch in the Source Control navigator. Now it shows the new branch as the 'current' branch.

If you branch off version 1.1, you won't have either version 1.2 or 1.3's changes. By adding just the 1.3 code, you will have 1.3's changes without 1.2's changes.

I realised that while we cannot roll back commits, we can checkout from an older commit. Its a good thing that I can still access the code I had written, even if it wasn't of use. Can I do this (and if so, how?)...


  1. Checkout from an older commit.
  2. mark the commits after the one I checkedout from as a branch.
  3. carry on in the existing branch as master branch.


Neerav