XCode - 有什么方法可以在“放弃更改”后恢复代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13478358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XCode - Any way to recover code after "Discard Changes"?
提问by bcreigh
I inadvertantly did a very stupid thing last night. I have been working on an iPad project for a couple of months and (even more stupidly) do not have a backup. By right-clicking on the project in XCODE, I mistakenly clicked "Discard Changes"
昨晚不经意间做了一件很蠢的事。我已经在 iPad 项目上工作了几个月并且(甚至更愚蠢)没有备份。通过在 XCODE 中右键单击项目,我错误地单击了“放弃更改”
(stupidity reigns again) I did not have any commits since the initial and when I did the Discard Changes, it seems that it went all the way back to the initial commit, which if I am looking at things correctly looks like each file is as it was the very first time it was saved.
(愚蠢再次占据上风)自最初以来我没有任何提交,当我进行放弃更改时,它似乎一直回到最初的提交,如果我正确地看待事情,看起来每个文件都是这是它第一次被保存。
My question is: Is there a way to recover my work? Is it in the .git directory? Is a copy stored elsewhere? or as a last resort, any chance to recover some of the source text with an un-delete utility?
我的问题是:有没有办法恢复我的工作?它在 .git 目录中吗?副本是否存储在其他地方?或者作为最后的手段,有机会使用取消删除实用程序恢复某些源文本吗?
Thanks,
谢谢,
Bob
鲍勃
采纳答案by bcreigh
Well luck was on my side after all. As it turns out, when I did the Source Control > Discard Changes operation, it did not make any changes to the source code save in my project directory. I was able to start a new project and added the files back in. Once I did that I was able to compile and run my project in the simulator just as it was before the incident. I now have a backup as well as committed the changes in git.
毕竟运气站在我这边。事实证明,当我执行 Source Control > Discard Changes 操作时,它没有对保存在我的项目目录中的源代码进行任何更改。我能够开始一个新项目并重新添加文件。一旦我这样做了,我就能够在模拟器中编译和运行我的项目,就像在事件发生之前一样。我现在有一个备份并提交了 git 中的更改。
回答by Ammar Mujeeb
For little clarification.. one can put back files from the trash as discard changes sends the file in the trash
稍微澄清一下..可以将文件从垃圾箱中放回,因为丢弃更改将文件发送到垃圾箱中
回答by Michael Dautermann
You have a hope of fetching this code if you "pushed" & committed your prior-to-discarded changes into your local git repository. Or if you're using MacOS's included Time Machineor some other automated backup solution.
如果您将之前丢弃的更改“推送”并提交到本地 git 存储库,则您希望获取此代码。或者,如果您使用的是 MacOS 附带的Time Machine或其他一些自动备份解决方案。
Aside from that, you might be hosed.
除此之外,你可能会被灌水。
回答by BJ Homer
If you're on Lion or later, you may have Time Machine backups even if you don't have an external drive. As of Lion, Time Machine will take 'local snapshots' of files; this is how they support the "Versions" feature that lets you go back to previous versions of your files.
如果您使用的是 Lion 或更高版本,即使您没有外部驱动器,您也可能拥有 Time Machine 备份。从 Lion 开始,Time Machine 将拍摄文件的“本地快照”;这就是他们如何支持“版本”功能,让您返回到文件的先前版本。
If you didn't have Time Machine turned on, though... you may be out of luck.
但是,如果您没有打开 Time Machine,那么……您可能不走运。
回答by batgun
Answer copied from How to undo xcode discard all changes if not committed
从如何撤消 xcode 如果未提交则丢弃所有更改中复制的答案
Quit Xcode. Open the file you wish to bring back your lost changes to using TextEdit. Go to File -> Revert To -> Browse All Versions... Scroll through the available versions. Hopefully you will have many available to choose from. Select a version and hit Restore. Follow 1-5 for all necessary files. Launch Xcode. You should now see the M next to these files in Project Navigator indicating they include uncommited changes (the changes you previously discarded). Completely new files you may have created and were discarded can be found in the Trash.
退出 Xcode。打开您希望使用 TextEdit 恢复丢失更改的文件。转到文件 -> 还原为 -> 浏览所有版本...滚动浏览可用版本。希望您将有许多可供选择。选择一个版本并点击恢复。对于所有必需的文件,请按照 1-5 进行操作。启动 Xcode。您现在应该在 Project Navigator 中看到这些文件旁边的 M 表示它们包含未提交的更改(您之前丢弃的更改)。您可能已经创建并被丢弃的全新文件可以在废纸篓中找到。
Also a small piece of advice. If you are in need to discard changes, prefer using Source Control -> Discard Changes by right clicking on files in the Project Navigator, instead of Discard All Changes which might give you all kinds of trouble.
还有一个小小的建议。如果您需要放弃更改,更喜欢使用 Source Control -> Discard Changes 通过右键单击 Project Navigator 中的文件,而不是 Discard All Changes,这可能会给您带来各种麻烦。
Have a nice day. :)
祝你今天过得愉快。:)

