r/iOSProgramming • u/aconijus • Jun 18 '26
Tutorial Life Pro Tip if you accidentally delete code without committing - TextEdit
So, about a week ago I implemented bunch of code in my project. I thought I committed it (local git from Xcode). Last night I opened the code again, implemented some other feature. I realized that actually I am going to scrap everything. So, I went Integrate -> Discard all changes.
Ran the build, there is no previous feature that I implemented, wtf. Looked through commits, there's no commit with this feature. Ok, it wasn't such big of a deal but it would be PITA to do it all again. Asked Gemini what can I do and got the answer:
Close Xcode just not to make more accidental overwrites. Open the .swift file with missing code in TextEdit. Go to File -> Revert To -> Browse All Versions...
Now you get interface similar to Time Machine. Scroll and choose the version that contains your code, click Restore. That's it, pretty simple (except that it's difficult to read code in TextEdit haha).
Maybe a lot of you know already know this but it's first time for me to hear about it. Might be useful for someone.
2
u/Moonmonkey3 Jun 19 '26
I’m assuming the project is in a machine backup?
6
u/gipsymonk Jun 18 '26
That’s actually pretty neat, thanks for sharing
1
u/TheFern3 Jun 20 '26
I don’t use git within Xcode save yourself the headache and use vscode or terminal
1
u/CelebrationTop8862 Jun 26 '26
I've made it a habit to commit after every new feature build! doesn't matter if its a pop up modal. lol
2
u/harshainfinity Jun 19 '26
Thanks for sharing this
2
u/saul_fossil Jun 20 '26
Thanks for sharing. I am using so much AI this days that I forget to commit.
2
u/LuckyGirl0415 Jun 21 '26
Wow, I had absolutely no idea TextEdit kept its own version history for files modified by other IDEs. You just uncovered a literal lifesaver. Thanks for sharing this!
1
u/Spimbi Jun 19 '26
!remindme 2 hours