开发笔记--git代码回退,撤回到上一个版本
场景描述:
培训环境系统升级,更新代码后,发现更新记录中有部分变更代码可能存在问题,为了不影响系统正常访问,想要将代码撤回到更新前的状态,如何操作?
利用git reset命令!
操作步骤:
1. git log查看更新日志
2. git reset b2345avgf370 ---还原到上个版本,指定的commit id序号就可以
root@test9120b:/mnt# git log commit c6243dfc6370001sdfsf445b1fac4c28ac9694c3d6 Merge: 05a11d0 c1277b6 Author:test <dfsfsdfsfsfs.com> Date: Sat Jun 27 22:03:27 2020 +0800 Merge remote-tracking branch 'origin/gk_0613' into test_dev commit b2345avgf370001sdfsf445b1fac4c28ac9694c3d6 Merge: 05a11d0 c1277b6 Author:test <dfsfsdfsfsfs.com> Date: Sat Jun 23 20:00:22 2020 +0800 Merge remote-tracking branch 'origin/gk_0606' into test_dev
。。。。
。。。。
在服务端git pull之后,回退操作:
root@321313131:/mnt/extra-addons# git reflog 9de33dc HEAD@{0}: reset: moving to 9de33dcda9c662970325988f347264d32626d20e 065bba2 HEAD@{1}: pull origin service_provider_dev: Fast-forward ca9747e HEAD@{2}: pull origin service_provider_dev: Fast-forward 84d298d HEAD@{3}: pull origin service_provider_dev: Fast-forward b9da8a6 HEAD@{4}: pull origin service_provider_dev: Fast-forward 55c5932 HEAD@{5}: pull origin service_provider_dev: Fast-forward 96a33f0 HEAD@{6}: pull origin service_provider_dev: Fast-forward 7196de3 HEAD@{7}: pull origin service_provider_dev: Fast-forward ....... root@321313131:/mnt/extra-addons# git reset --hard HEAD@{2} ***这里的HEAD@{2}就是操作前上一个版本的提交ID HEAD is now at ca9747e gzj20220422