简体   繁体   English

找回意外git恢复删除的文件

[英]Getting back files deleted by an accidental git revert

I was trying to push my code to my git but accidentally did a git revert. 我试图将代码推送到我的git,但是不小心将git恢复了。 It looks like this: 看起来像这样:

[master 36aff31] Revert "Addded files"
 54 files changed, 44739 deletions(-)
 delete mode 100644 myfolder/.DS_Store
 delete mode 100644 myfolder/1198232958151161470_462274348.jpg
 delete mode 100644 myfolder/localfile.py
 ................
 ................

I did a git checkout . 我做了一个git checkout . in order to get files back but nothing happened. 为了找回文件,但什么也没发生。 How can I get my files back? 如何找回文件?

If you want to keep your commit history clean while undoing your accidental git revert , you can use git reset with the --hard option to set the state of your working directory back to the commit immediately before the current (revert) commit ( HEAD^ ): 如果要在清除意外的git revert时保持提交历史记录干净,则可以将git reset--hard选项一起使用,以将工作目录的状态设置为--hard在当前(恢复)提交之前的提交( HEAD^ ):

git reset --hard HEAD^

NB: be sure that you haven't made any other commits since the accidental commit or this will discard those changes from your working directory. 注意:请确保自意外提交以来没有进行任何其他提交,否则将丢弃工作目录中的那些更改。

If you don't care about a clean commit history, running a second git revert is probably safer. 如果您不关心干净的提交历史记录,则运行第二个git revert可能更安全。

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

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