上一篇博客写了一个new.txt文件,提交到了Git版本库,现在修改一下,内容如下:
Git is a version control system.
Git is free distributed under the GPL.
然后用“add”,“commit”命令提交
$ git add new.txt
$ git commit -m "append GPL"
[master 85eabe3] append GPL
1 file changed, 1 insertion(+), 1 deletion(-)
这样修改后,就有两个版本被提交到了Git仓库中
版本一:wrote a readme file
Git is a version control system.
Git is free.
版本二:append GPL
Git is a version control system.
Git is free distributed under the GPL.
可以git log 命令查看日志:
$ git log
commit 85eabe37730c337311057eed8e286ceb147d135f (HEAD -> master)
Author: lzg <2394391141@qq.com>
Date: Tue Oct 6 12:47:45 2020 +0800
append GPL
commit 41088614c8ff0370face6248c1d9fc626d4eb45a
Author: lzg <2394391141@qq.com>
Date: Mon Oct 5 20:28:45 2020 +0800
wrote a readme file
从上到下是最近到最久的提交
你看到的一大串类似85ea…的是commit id(版本号)
我们要把当前版本append GPL回退到上一个版本就可以使用git reset命令:首先,Git必须知道当前版本是哪个版本,在Git中,用HEAD表示当前版本,也就是最新的提交85ea…(注意我的提交ID和你的肯定不一样),上一个版本就是HEAD^ ,上上一个版本就是HEAD^^ ,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。
回退后想回到新版本也是可以的找到那个append GPL的commit id是85ea…
想要找到append GPL的commit id。Git提供了一个命令git reflog用来记录你的每一次命令:
学习自https://www.liaoxuefeng.com/wiki/896043488029600/897013573512192