从 SourceTree 或 Git 恢复已删除的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16144022/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:27:45  来源:igfitidea点击:

Restore Deleted Files from SourceTree or Git

gitatlassian-sourcetree

提问by cpdt

I have recently started using SourceTree to work with Bitbucket. I was working on a project, and then I decided I needed to move it to a different folder (for various reasons). So, I cut the files that I was working on in the repo, and then clicked the delete button in SourceTree, not realising that doing this would actually delete the files. I cut the files just in case, but didn't remember that pasting these files requires the original files to exist.

我最近开始使用 SourceTree 来处理 Bitbucket。我正在处理一个项目,然后我决定需要将它移动到不同的文件夹(出于各种原因)。所以,我剪切了我在 repo 中处理的文件,然后单击 SourceTree 中的删除按钮,没有意识到这样做实际上会删除文件。我剪切了文件以防万一,但不记得粘贴这些文件需要原始文件存在。

Now, I only have the files left from repo that SourceTree did not delete.. these are the files in the objectsdirectory, and I do not have the infoor packfolders that are inside the objectsdirectory.

现在,我只有 SourceTree 没有删除的 repo 留下的文件。这些是目录中的objects文件,我没有目录中的infopack文件夹objects

Is there any way that I can restore the files? I have taken a look at this questionand this question, however I am new to git and cannot figure out how to actually do these.

有什么办法可以恢复文件吗?我已经看过这个问题这个问题,但是我是 git 的新手,无法弄清楚如何实际执行这些操作。

Please help! How can I restore the files in the repo?

请帮忙!如何恢复 repo 中的文件?

采纳答案by cpdt

If that files were committed you can just make git checkout HEAD -f.
If files were not committed they are not stored as objects.

如果该文件已提交,您只需 make git checkout HEAD -f
如果文件未提交,则它们不会存储为对象。