恢复删除的文件
问题描述:
我想恢复到我以前的承诺(承诺4d462937b006da1fbc710bc33bf3bab76de1ede2)与我的所有文件(其中一些已被删除)恢复删除的文件
(venv) [[email protected]_arch project]$ git log
commit d0b07921e818c5c5abdb92f0e563f4d186370b6f
Author: Nikos Dalezios <[email protected]>
Date: Tue Mar 1 21:03:11 2016 +0200
test
commit 4d462937b006da1fbc710bc33bf3bab76de1ede2
Author: Nikos Dalezios <[email protected]>
Date: Sun Feb 28 20:07:01 2016 +0200
ok
(venv) [[email protected]_arch project]$ git reflog
d0b0792 [email protected]{0}: pull origin master: Fast-forward
4d46293 [email protected]{1}: reset: moving to 4d46293
e0e0368 [email protected]{2}: reset: moving to HEAD^
4d46293 [email protected]{3}: reset: moving to 4d46293
d0b0792 [email protected]{4}: checkout: moving from 4d462937b006da1fbc710bc33bf3bab76de1ede2 to d0b0792
4d46293 [email protected]{5}: checkout: moving from master to 4d46293
4d46293 [email protected]{6}: reset: moving to HEAD^
d0b0792 [email protected]{7}: commit: test
4d46293 [email protected]{8}: commit: ok
我真的把事情搞乱了,我失去了一些文件的Python代码(几百行)。 HEAD @ {8}是我需要回去点.....
感谢
我不知道这是否可以帮助,但我的命令历史是这样的
git rm -r *
git reset --hard HEAD
git reset HEAD
git commit -a
git reset --hard HEAD^
git checkout 4d46293
git checkout d0b0792
git reset --hard 4d46293
git reset --hard HEAD^ #4d46293
答
如果您还没有推你提交到你的远程仓库,但(Github上,到位桶,等等。),那么你可以使用
git reset --hard 4d462937b006da1fbc710bc33bf3bab76de1ede2
这基本上删除了与您的提交相关的任何记录。
如果,另一方面,你已经推你的提交到远程仓库,那么你会想要做
git revert 4d462937b006da1fbc710bc33bf3bab76de1ede2
其撤消更改并记录该撤消在提交历史。
答
git reset --hard 4d462937b006da1fbc710bc33bf3bab76de1ede2
+0
好的,但我删除的文件仍然失踪..... –
Duplicated http://stackoverflow.com/questions/4114095/revert-git-repo-to-a-previous-commit –