1.多次修改某個文件,並提交
2.使用git log 查看提交日誌
$ git log
commit 1094adb7b9b3807259d8cb349e7df1d4d6477073 (HEAD -> master)
Author: Michael Liao <[email protected]>
Date: Fri May 18 21:06:15 2018 +0800
append GPL
commit e475afc93c209a690c39c13a46716e8fa000c366
Author: Michael Liao <[email protected]>
Date: Fri May 18 21:03:36 2018 +0800
add distributed
commit eaadf4e385e865d25c48e7ca9c8395c3f7dfaef0
Author: Michael Liao <[email protected]>
Date: Fri May 18 20:59:18 2018 +0800
wrote a readme file
開始回退:
1.使用git reset
--hard HEAD^命令回退到上一個版本:
$ git reset --hard HEAD^
HEAD is now at e475afc add distributed
2.使用 git reset --hard commitID 回退到指定版本:
$ git reset --hard eaadf
ID不用寫全,只要能和其他的不重複即可
3.回退後悔了,使用 git reset --hard commitID 回到新版本:
(1)若當前命令窗口沒關,往上拉查看新版本的commit id;
(2)若命令窗口已經關閉,使用命令git reflog
:(命令git reflog
用來記錄你的每一次命令:)
$ git reflog
e475afc HEAD@{1}: reset: moving to HEAD^
1094adb (HEAD -> master) HEAD@{2}: commit: append GPL
e475afc HEAD@{3}: commit: add distributed
eaadf4e HEAD@{4}: commit (initial): wrote a readme file