1

This is a question that I posted, and then after much digging finally resolved myself. There is actually quite a bit on this subject both on this forum and elsewhere, but it usually requires some familiarity with Terminal. I am going to describe the problem I faced and then describe step-by-step in detail (at a beginner's level) how to resolve the issue in Terminal.

In short, I checked out a previously committed version of my app in Xcode, which - because it was a version from several weeks prior - did not contain my most recent commits. In other words, I had no access to any of the commits that contained my most recent work. They had all disappeared.

My commits and pushes had not stored in GitHub because presumably some time before this I had accidentally selected my main folder as the destination for my commits, rather than one of the two branches I created. So I had absolutely no access to my work. By all appearances I pretty much had to start from scratch.

After much hand wringing, teeth gnashing, and hours of scouring the webs, I finally uncovered the solution. But it takes a bit of understanding about Terminal to make it work. So after several more hours of learning Terminal, I finally successfully restored all of my work.

For any of you who are new to coding (as I am), and who have no experience with Terminal, I will provide detailed instructions on how to resolve this issue if you encounter it in the answer below.

TJ Rogers
  • 500
  • 1
  • 6
  • 19
  • Thanks for your responses. Just to clarify, I don't think any of these commits ever made it to GitHub. I think they never made it past some repository in Xcode, so if they are anywhere they are local. I don't recall what message I may have gotten so I can't speak to the stashed status. As to how I checked out, I selected the Source Control Navigator Icon in the left pane. This populated all of my commits (which never made it to GitHub). To check out the commit I right-clicked one of the commits and clicked "Checkout [alphanumeric code]." Hope this sheds some light on the situation. – TJ Rogers Jan 10 '21 at 03:10
  • I figured it out and restored my work! Thanks to the two commenters whose remarks prodded me to keep digging for my own solution. I will reframe this post to describe the issue I was having, and then post how I resolved the problem. – TJ Rogers Jan 10 '21 at 04:05

1 Answers1

1
  1. Open Terminal to prompt to your Xcode project. The easiest way to do this is to find your project in Finder, which will have a .xcodeproj extension, and then right click it.

  2. Select New Terminal at Folder.

  3. At this point, a terminal window will pop up. From here, enter the following: git reflog

  4. Press Enter

  5. This will populate a list of all the commits stored in your Xcode project. Each commit is identified by an alphanumeric code (the one I restored was 1a7ea33, for example).

  6. Note the alphanumeric code of the commit you wish to restore.

  7. After this, enter the following: git checkout -b NewBranch 1a1a1a1 (where "NewBranch" is whatever name you decide to name your new branch, and "1a1a1a1" is your alphanumeric code from steps 5 and 6).

  8. Press Enter.

That's it. Close Terminal and open your Xcode project as normal. You will notice the restored commit in the folder you just named in Terminal.

Hopefully no one will ever need this, but if by chance someone does I hope it helps.

TJ Rogers
  • 500
  • 1
  • 6
  • 19