git 代码回滚

442 阅读1分钟

1、回滚到上一版本

$ git reset --hard HEAD~1 

2、回滚到任一版本

先显示提交的log

$ git log -3

commit 9b786cb7790103d1dd9d5b17f38ddc
Author: xxx <xxx@xx.com>
Date:   Wed Mar 14 18:21:02 2018 +0800

    xxxxx

commit 08f27bb1469c3704b401e321c438ac
Author: xxxx<xx@xx.com>
Date:   Tue Mar 13 21:14:52 2018 +0800

    improved the requst

commit 2ffdf2a3dd4d34d928d7fdb7734ed
Author: xxx<xxx@xx.com>
Date:   Tue Mar 13 15:29:14 2018 +0800

回滚到指定版本

$ git reset --hard 08f27bb1469c3704b401e321c438ac

强制提交

$ git push -f origin master