Git checkout — recover lost files

点点圈 提交于 2019-12-12 03:37:06

问题


I accidentaly deleted local file changes on git repository. They were NOT commited or even pushed.

What I did: git status (then files not staged for commit showed and I accidentaly removed whole folder called "smdr" by this comand): git checkout -- smdr

Then files changes disappeared.

How can I recover those files (birng everything back before that git checkout -- smdr comand)?


回答1:


You can't with Git. The files were not committed so they are not in history. You just got the (inexistant) version in the index with git checkout.

Your only hope is your backup system.




回答2:


You can use any of the given options:

Git reflog

Type git reflog and checkout the commit you need, it will "revert" your repository to the "deleted" commit.

Git revert

Another option is use git revert SHA-1 which will revert your commit. It will simply undo your changes

Git reset

Git reset will checkout the content of the given sha-1. It will set your branch to be at the same state as the SHA-1



来源:https://stackoverflow.com/questions/30643119/git-checkout-recover-lost-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!