Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restoring an Xcode commit that was never pushed to Github

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.

like image 619
TJ Rogers Avatar asked Sep 25 '26 11:09

TJ Rogers


1 Answers

  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.

like image 73
TJ Rogers Avatar answered Sep 27 '26 06:09

TJ Rogers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!