git reset --hard 之 git版本回退
学习笔记,参考:https://blog.csdn.net/themagickeyjianan/article/details/78923322
1.假设有2个提交记录
commit def5adef853da4cc05752bdb36577c127be71ba5
Author: 132982jianan <[email protected]>
Date: Thu Dec 28 16:01:36 2017 +0800
add data to 1.txt
commit f36801544670e00b2f59a28e19017d2786c4085e
Author: 132982jianan <[email protected]>
Date: Thu Dec 28 15:59:46 2017 +0800
init 1.txt
(END)
2.现在回到最开始的那一个提交
git reset --hard f36801544670e00b2f59a28e19017d2786c4085e
3.查看日志,就会发现只剩下一个提交了
git log
commit f36801544670e00b2f59a28e19017d2786c4085e
Author: 132982jianan <[email protected]>
Date: Thu Dec 28 15:59:46 2017 +0800
init 1.txt
(END)
4.这个时候,发现回退版本错了,那么就用git reflog查看提交记录
git reflog
f368015 HEAD@{0}: reset: moving to f36801544670e00b2f59a28e19017d2786c4085e
def5ade HEAD@{1}: reset: moving to def5ade
f368015 HEAD@{2}: reset: moving to f36801544670e00b2f59a28e19017d2786c4085e
def5ade HEAD@{3}: commit: add data to 1.txt
f368015 HEAD@{4}: commit (initial): init 1.txt
5.找出想要回退的版本,进行回退
恢复
git reset --hard def5ade