1. 程式人生 > >git reset --hard 之 git版本回退

git reset --hard 之 git版本回退

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 [email protected]
{0}: reset: moving to f36801544670e00b2f59a28e19017d2786c4085e
def5ade [email protected]{1}: reset: moving to def5ade
f368015 [email protected]{2}: reset: moving to f36801544670e00b2f59a28e19017d2786c4085e
def5ade [email protected]{3}: commit: add data to 1.txt
f368015 [email protected]{4}: commit (initial): init 1.txt

5.找出想要回退的版本,進行回退

恢復

git reset --hard def5ade