type
status
date
slug
summary
tags
category
icon
password
😀
本节内容主要包含:git版本回退基础操作。
 

📝 流程展示

时光穿梭机——版本回退

1.这是使用git log过后的显示内容:
notion image
git log过后,commit 后面的那一串字符串就是相关的时间点序号 而(HEAD -> master)所在的位置就是我们当前所处于的位置。
2.这是使用git log --pretty=oneline过后的显示内容:
notion image
一行就是一个时刻,简化了git log显示的内容。
通过上面两个图片,我们也可以看出:写注释的重要性。如果没有注释,git log或者git log --pretty=oneline之后,就只有前面的字符串,我们就不好判断版本号了。
例如:我们要回到创建好第一个文件readme.txt的时候: 执行操作:
notion image
回退之前的目录文件状态:
notion image
回退之后的目录文件状态:
notion image
 
4.注意:回到过去之后,要想再回到之前最新的版本的时候,则需要使用指令去查看历史操作,以得到最新版本的commit id。 指令:git reflog
notion image
5.选择需要的版本对应的字符串,然后使用git reset –hard指令:
notion image
然后我们再打开目录文件,此时其状态:
notion image

🤗 总结归纳

  1. 要想回到过去,必须先得到commit id,然后通过git reset –hard进行回退;
  1. 要想回到未来,需要使用git reflog进行历史操作查看,得到最新的commit id;
  1. 在写回退指令的时候,commit id可以不用写全,git会自动识别,但是也不能写太少,至少需要写前4位字符。

📎 参考文章

 
💡
有关git安装或者使用上的问题,欢迎您在底部评论区留言,一起交流~
git本地仓库操作git基于http协议提交线上仓库
  • Giscus
  • Cusdis
  • Utterance
Naipings
Naipings
一个普通的大学生,分享自己学习的“有趣”知识
Announcement
type
status
date
slug
summary
tags
category
icon
password
🎉 感谢您的支持 🎉
-- 点击收藏不迷路 ---
👏欢迎更新体验👏