回退版本

版权声明:本文为博主THMAIL原创文章,未经博主允许不得转载。 https://blog.csdn.net/THMAIL/article/details/84196281

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

猜你喜欢

转载自blog.csdn.net/THMAIL/article/details/84196281
今日推荐