type
status
date
slug
summary
tags
category
icon
password
本节内容主要包含:git版本回退基础操作。
📝 流程展示
时光穿梭机——版本回退
1.这是使用git log过后的显示内容:

git log过后,commit 后面的那一串字符串就是相关的时间点序号
而(HEAD -> master)所在的位置就是我们当前所处于的位置。
2.这是使用git log --pretty=oneline过后的显示内容:

一行就是一个时刻,简化了git log显示的内容。
通过上面两个图片,我们也可以看出:写注释的重要性。如果没有注释,git log或者git log --pretty=oneline之后,就只有前面的字符串,我们就不好判断版本号了。
例如:我们要回到创建好第一个文件readme.txt的时候:
执行操作:

回退之前的目录文件状态:

回退之后的目录文件状态:

4.注意:回到过去之后,要想再回到之前最新的版本的时候,则需要使用指令去查看历史操作,以得到最新版本的commit id。
指令:git reflog

5.选择需要的版本对应的字符串,然后使用git reset –hard指令:

然后我们再打开目录文件,此时其状态:

🤗 总结归纳
- 要想回到过去,必须先得到commit id,然后通过git reset –hard进行回退;
- 要想回到未来,需要使用git reflog进行历史操作查看,得到最新的commit id;
- 在写回退指令的时候,commit id可以不用写全,git会自动识别,但是也不能写太少,至少需要写前4位字符。
📎 参考文章
有关git安装或者使用上的问题,欢迎您在底部评论区留言,一起交流~
- Author:Naipings
- URL:https://naipings.cn/article/git03
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts