插播个号外

mybatis分析系列文章(偏源码)

springboot系列文章(偏源码)

mybatis面试系列文章

以上文章都是纯原创,非转发,非抄袭!!!

1:背景介绍

我司有很多款产品,多款产品使用的是通过我们的一套系统来支持的,最近一个新产品上线因为数据过多出现了非常严重的性能问题,为了紧急解决这个问题,将系统调整为仅支持目前这一款产品的方式,稳定后因为其他产品也要上线,这时候就有问题了,代码已经不支持了,所以需要紧急恢复到之前的版本(这里说明下,该款产品不会引起性能问题),但是由于当时事发突然,没有来得及打分制,也就有了这篇文章的分享。

2:讲解方式

本文将会从无仓库,到最后恢复到历史版本一步一步的来进行,尽量让不同层次的读者都能有所收获。

3:正式开始

3.1: 在gitee创建仓库

3.2: 在本地创建仓库test-git-reset-to-old-version

3.2.1:创建test-git-reset-to-old-version文件夹

3.2.2:进入test-git-reset-to-old-version文件夹初始化仓库

$ pwd
/e/test/test-git-reset-to-old-versioncj@cj-PC MINGW64 /e/test/test-git-reset-to-old-version
$ git init
Initialized empty Git repository in E:/test/test-git-reset-to-old-version/.git/

3.2.3:创建文件11.txt并提交到本地

$ touch 11.txtcj@cj-PC MINGW64 /e/test/test-git-reset-to-old-version (master)
$ vim 11.txtcj@cj-PC MINGW64 /e/test/test-git-reset-to-old-version (master)
$ cat 11.txt
111$ git add 11.txt
warning: LF will be replaced by CRLF in 11.txt.
The file will have its original line endings in your working directory.
cj@cj-PC MINGW64 /e/test/test-git-reset-to-old-version (master)$ git commit -m '11 txt first commit'
[master (root-commit) 16cfe39] 11 txt first commit
warning: LF will be replaced by CRLF in 11.txt.
The file will have its original line endings in your working directory.1 file changed, 1 insertion(+)create mode 100644 11.txt

3.2.4:远程仓库建立管理

添加远程仓库格式为git remote add <你给远程仓库起的名字,一般指定为origin> 远程仓库地址,git remote -v该命令为查看远程仓库信息。

$ git remote add origin https://gitee.com/dongsir2020/test-git-reset-to-old-version.gitcj@cj-PC MINGW64 /e/test/test-git-reset-to-old-version (master)
$ git remote -v
origin  https://gitee.com/dongsir2020/test-git-reset-to-old-version.git (fetch)
origin  https://gitee.com/dongsir2020/test-git-reset-to-old-version.git (push)

3.2.5:推送到远程

$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 216 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
To https://gitee.com/dongsir2020/test-git-reset-to-old-version.git* [new branch]      master -> master

此时远程仓库变为:

3.3: 再次修改并提交

3.3.1:查看当前版本

git log --pretty=oneline用于通过显示一行的方式来查看git 日志。

$ git log --pretty=oneline
16cfe39c0b3f4898f1c01bb9a2e593aac1feb548 11 txt first commit

3.3.2:再次并提交推送到远程

内容修改为222

$ cat 11.txt
222$ git commit -m '111 txt second commit'
[master warning: LF will be replaced by CRLF in 11.txt.
The file will have its original line endings in your working directory.
22f8bc6] 111 txt second commit
warning: LF will be replaced by CRLF in 11.txt.
The file will have its original line endings in your working directory.1 file changed, 1 insertion(+), 1 deletion(-)$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 245 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
To https://gitee.com/dongsir2020/test-git-reset-to-old-version.git16cfe39..22f8bc6  master -> master

3.3.3:再次查看日志

$ git log --pretty=oneline
22f8bc66fcfa47eee2d6b1f1d5b026c0c00e58ab 111 txt second commit
16cfe39c0b3f4898f1c01bb9a2e593aac1feb548 11 txt first commit

3.3.4:恢复到第一个版本

恢复到版本16cfe39c0b3f4898f1c01bb9a2e593aac1feb548该信息可以在git log中获取,实际操作就是你要恢复到的那次提交ID的值,使用的名称为git reset --hard <commit ID>

$ git reset --hard 16cfe39c0b3f4898f1c01bb9a2e593aac1feb548
HEAD is now at 16cfe39 11 txt first commit

需要注意的是因为我们已经推送了远程,在禁用-f的情况无法强制推送,这时候的解决方案是,在该历史版本基础上直接建立分支,然后推送到远程仓库即可。

3.4: 使用恢复的历史版本开发

3.4.1:打出新分支

命令为git checkout -b <new branch name>,该命令同时完成了打新分支+切换分支的工作=git branch + git checkout。命令git branch -a用于查看所有的分支即本地分支+远程分支

$ git checkout -b the-old-version
Switched to a new branch 'the-old-version'$ git branch -amaster
* the-old-versionremotes/origin/master

可以看到当前的本地分支有master,the-old-version,远程分支有remotes/origin/master,其中本地分支the-old-version为当前分支。

3.4.2:将新分支推送到远程

命令为git push <远程仓库名称> <要推送的本地分支名称>:<远程仓库名称(自己随意起)>,一般本地和远程名称保持一致,但是本例中为自定义的,建议工作中使用保持一致的方式。

$ git push origin the-old-version:the-old-version-remote
Total 0 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
remote: Create a pull request for 'the-old-version-remote' on Gitee by visiting
remote:     https://gitee.com/dongsir2020/test-git-reset-to-old-version/pull/new/dongsir2020:the-old-version-remote...dongsir2020:master
To https://gitee.com/dongsir2020/test-git-reset-to-old-version.git* [new branch]      the-old-version -> the-old-version-remote

再次使用命令git branch -a查看所有分支:

$ git branch -amaster
* the-old-versionremotes/origin/masterremotes/origin/the-old-version-remote

可以看到远程分支中已经增加了分支remotes/origin/the-old-version-remote,直接到gitee查看如下图:

5:都让开,我要喝瑞幸

git如何恢复到历史版本相关推荐

  1. Github使用之git回退到某个历史版本

    1. 查找历史版本 使用git log命令查看所有的历史版本,获取你git的某个历史版本的id 假设查到历史版本的id是fae6966548e3ae76cfa7f38a461c438cf75ba965 ...

  2. Git回退到某个历史版本

    Git回退到某个历史版本 本人前段时间commit代码的时候,不小心commit一些本地的文件上去,并且还推到了开发分支代码,导致同事无法拉取代码,只能够回退版本了.注意,在回退版本之前,请复制粘贴你 ...

  3. SVN入门第三讲——SVN恢复到历史版本

    经过上一讲的学习,相信大家已经会简单使用SVN了,并且在上一讲中我还举了一个案例来演示.在上一讲的结尾处,我给大家留了一个悬念,某个开发人员(例如bb用户)从服务器上更新下来的代码有错,他想恢复到历史 ...

  4. GIT的使用总结/GIT如和获取历史版本项目

    GIT 是一个多人同时开发的工具,团队之间互助开发. git只是一个版本控制软件,负责记录本地的代码版本,并且建立本地仓库存储. 负责存储的是云端代码记录网址 GitHub或者码云 GitHub是li ...

  5. git 回退到某个历史版本

    git log 命令 查看所有历史版本,获取某个历史版本 id 号 假设查到历史版本 id 号是 9a36dde46453c7e93a72d073646fd24a1064e21c git log 状态 ...

  6. idea 使用 git 回退到某个历史版本

    有时我们提交错了,想回滚 怎么办? 一.用idea工具: 1.idea中打开Terminal:输入:git log   显示历史提交记录.或者 (右击项目--> Git --> Show ...

  7. idea git回退到某个历史版本

    1.找到要回退的版本号(右击项目--> Git --> Show History -->选中要回退的版本-->Copy Revision Number) 2.打开idea的Te ...

  8. 回退服务器文件版本,Git回退到服务器某个版本正确姿势

    背景: Git协作中,成员不可避免地会提交一些错误的版本,由于Git相比SVN引入了本地仓库,操作会相对复杂,以下为姿势分解 找一个源文件RspUtils.java,加上一行注释 //测试回退git服 ...

  9. git回退历史版本无法上传_Git系列教程(二):版本库中添加文件、版本回退

    Git系列教程(一):简介.安装.配置我们学习了分布式和版本控制系统的概念.Git具有的8个功能以及如何在Windows上安装Git.进行相关配置并创建版本库. Git版本库中添加文件 Git 的工作 ...

最新文章

  1. empty、isset和is_null的比较
  2. 去掉字符串里特殊字符的正则表达式方求
  3. getrlimit读取进程能打开的最大文件描述符
  4. 通过组策略实现客户端注册证书
  5. create-react-app项目使用假数据
  6. 关于RESTful一些注意事项,接口开发规范
  7. 苹果新技术或让无线充电更便捷
  8. Java Web学习总结(14)——JSP基础语法
  9. 搭建一个简单repo服务器
  10. 东京disney sea流水账 2
  11. android开发案例1---拦截电话,拯救史迪仔,有序广播
  12. r语言 月度消费频次_R语言基础-数据分析及常见数据分析方法
  13. matlab 球体的绘制 柱面坐标系法 球面坐标系法
  14. JS中常见的兼容写法
  15. 北漂生活第十四弹-5.24 兜兜转转又是一周
  16. vs2015 相关
  17. 远程IT运维的升级,“团队协作”
  18. [BZOJ3572][Hnoi2014]世界树 虚树+DP
  19. 微信小程序---搜索功能并跳转搜索结果页面
  20. php的strtoupper,关于PHP的strtoupper函数

热门文章

  1. 从阿里云到自建:RocketMQ迁移的注意事项
  2. 在培训班里学IT技术,真的有用吗?
  3. 大学生做什么副业好?大学生可以做哪些副业?
  4. php删除文件夹及其文件夹下所有文件
  5. 微信小程序做Table表格
  6. JAVA之坦克大战(二)我方坦克移动
  7. 数据降维几种方法,主成分分析学习和代码实现
  8. django-simple-captcha验证码的验证问题
  9. php 0.01毫米对折,全球首创:0.01毫米最薄柔性显示屏,手机可以折叠成腕表!
  10. 测试开发工程师必问面试题