mybatis分析系列文章(偏源码)
springboot系列文章(偏源码)
mybatis面试系列文章
以上文章都是纯原创,非转发,非抄袭!!!
我司有很多款产品,多款产品使用的是通过我们的一套系统来支持的,最近一个新产品上线因为数据过多出现了非常严重的性能问题,为了紧急解决这个问题,将系统调整为仅支持目前这一款产品的方式,稳定后因为其他产品也要上线,这时候就有问题了,代码已经不支持了,所以需要紧急恢复到之前的版本(这里说明下,该款产品不会引起性能问题),但是由于当时事发突然,没有来得及打分制,也就有了这篇文章的分享。
本文将会从无仓库,到最后恢复到历史版本一步一步的来进行,尽量让不同层次的读者都能有所收获。
略
。
$ pwd
/e/test/test-git-reset-to-old-version
cj@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/
11.txt
并提交到本地$ touch 11.txt
cj@cj-PC MINGW64 /e/test/test-git-reset-to-old-version (master)
$ vim 11.txt
cj@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
添加远程仓库格式为git remote add <你给远程仓库起的名字,一般指定为origin> 远程仓库地址
,git remote -v
该命令为查看远程仓库信息。
$ git remote add origin https://gitee.com/dongsir2020/test-git-reset-to-old-version.git
cj@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)
$ 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
git log --pretty=oneline
用于通过显示一行的方式来查看git 日志。
$ git log --pretty=oneline
16cfe39c0b3f4898f1c01bb9a2e593aac1feb548 11 txt first commit
内容修改为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.git
16cfe39..22f8bc6 master -> master
$ git log --pretty=oneline
22f8bc66fcfa47eee2d6b1f1d5b026c0c00e58ab 111 txt second commit
16cfe39c0b3f4898f1c01bb9a2e593aac1feb548 11 txt first commit
恢复到版本16cfe39c0b3f4898f1c01bb9a2e593aac1feb548
该信息可以在git log中获取,实际操作就是你要恢复到的那次提交ID的值,使用的名称为git reset --hard
:
$ git reset --hard 16cfe39c0b3f4898f1c01bb9a2e593aac1feb548
HEAD is now at 16cfe39 11 txt first commit
需要注意的是因为我们已经推送了远程,在禁用-f
的情况无法强制推送,这时候的解决方案是,在该历史版本基础上直接建立分支,然后推送到远程仓库即可。
命令为git checkout -b
,该命令同时完成了打新分支+切换分支的工作=git branch + git checkout
。命令git branch -a
用于查看所有的分支即本地分支+远程分支
。
$ git checkout -b the-old-version
Switched to a new branch 'the-old-version'
$ git branch -a
master
* the-old-version
remotes/origin/master
可以看到当前的本地分支有master
,the-old-version
,远程分支有remotes/origin/master
,其中本地分支the-old-version
为当前分支。
命令为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 -a
master
* the-old-version
remotes/origin/master
remotes/origin/the-old-version-remote
可以看到远程分支中已经增加了分支remotes/origin/the-old-version-remote
,直接到gitee查看如下图: