git pull 后如何快速回滚

git
文章目录

本文最后更新于 <span id="expire-date"></span> 天前,文中部分描述可能已经过时。

在服务器执行 git pull 后发现生产环境报错,急需回滚到上一个安全版本,这时候我们需要运行 git reflog 命令查看你的历史变更记录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[root@user www.xxx.com]# git reflog
efb4b67 HEAD@{0}: pull: Fast-forward
fb7675d HEAD@{1}: pull: Fast-forward
77d8371 HEAD@{2}: pull: Fast-forward
3fa69a3 HEAD@{3}: pull: Fast-forward
fa72965 HEAD@{4}: pull: Fast-forward
ffe128e HEAD@{5}: pull: Fast-forward
c511308 HEAD@{6}: pull: Fast-forward
ef21f31 HEAD@{7}: pull: Fast-forward
8082a1b HEAD@{8}: pull: Fast-forward
7551f60 HEAD@{9}: pull: Fast-forward
0486156 HEAD@{10}: pull: Fast-forward
2be1fb0 HEAD@{11}: pull: Fast-forward
b3aec43 HEAD@{12}: pull: Fast-forward
c3318a4 HEAD@{13}: pull: Fast-forward
8ab54e1 HEAD@{14}: pull: Fast-forward
966c7ae HEAD@{15}: pull: Fast-forward
2e8a177 HEAD@{16}: pull: Fast-forward
5800282 HEAD@{17}: pull: Fast-forward
3e70800 HEAD@{18}: pull: Fast-forward
e4f45d9 HEAD@{19}: pull: Fast-forward
9069d11 HEAD@{20}: pull: Fast-forward
8b45ce5 HEAD@{21}: pull: Fast-forward
95a2d13 HEAD@{22}: pull: Fast-forward
d6ac3b6 HEAD@{23}: reset: moving to origin/master
99213c9 HEAD@{24}: pull: Fast-forward
d9b90ca HEAD@{25}: reset: moving to origin/master
d7258c4 HEAD@{26}: clone: from https://e.coding.net/xxxxxxxxxxxxxxxxxxxxxx.git

最上面的那条记录就是问题的那次,我们需要回滚到上一次,即 fb7675d 这里,输入如下指令即可:

1
git reset --hard fb7675d

本文作者:NightingaleWK

本文链接: https://www.wkarrow.top/GitCheckoutLastChange.html