简体   繁体   English

恢复已删除的文件

[英]Restore deleted files

I had a lot of files in directory public/uploads/. 我在目录public / uploads /中有很多文件。 Before commit I typed git rm -- public/uploads/* and then git commit -a -m "upload" and then git push origin master . 在提交之前,我输入git rm -- public/uploads/* ,然后输入git commit -a -m "upload" ,然后输入git push origin master In previous commit photos are not present. 在以前的提交中,不存在照片。 Now I want to restore them back from git to server. 现在,我想将它们从git还原回服务器。 How can I do that? 我怎样才能做到这一点?

You cannot recover them if they were never added or committed. 如果从未添加或提交它们,则无法恢复它们。

Let's say the hash of the commit where you deleted them is abc123. 假设您在其中删除提交的哈希值是abc123。 If you want to undo the whole commit, simply do git revert abc123 . 如果要撤消整个提交,只需执行git revert abc123 If there were other parts of the commit you want to keep, do: 如果要保留提交的其他部分,请执行以下操作:

git revert abc123 --no-commit
git reset
git add public/uploads/
git commit

Then the files will be back in the repository. 然后,文件将返回到存储库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM