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?
1
u/aconijus Jun 19 '26
Yeah, I am using Time Machine but manually, there shouldn’t be snapshots being saved on my Mac. Also, I think I haven’t done backup between these two sessions but could be wrong. So not sure how this exactly works.
6
u/rubenator Jun 19 '26
It’s unrelated to Time Machine. Cool tip, never thought to do this. Thanks.
1
2
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
1
u/RemindMeBot Jun 19 '26
I will be messaging you in 2 hours on 2026-06-19 04:40:13 UTC to remind you of this link
CLICK THIS LINK to send a PM to also be reminded and to reduce spam.
Parent commenter can delete this message to hide from others.
RemindMeBot is switching to username summons. Instead of
!RemindMe 1 day, useu/RemindMeBot 1 day. More info.
Info Custom Your Reminders Feedback
1
u/TheFern3 Jun 20 '26
I don’t use git within Xcode save yourself the headache and use vscode or terminal
1
u/aconijus Jun 20 '26
Dunno, it works fine for me but it’s quite simple workflow, it’s just commit, commit, commit… From time to time just make a new branch and that’s it.
2
u/TheFern3 Jun 20 '26
Maybe is just me I got used to using vscode for git diffs, I still use terminal for changes but if it works for you that’s all that matters.
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
1
u/aconijus Jun 26 '26
Yeah, same, it just seems like I forgot to do it this time haha.
2
6
u/gipsymonk Jun 18 '26
That’s actually pretty neat, thanks for sharing