1.git reset
回到某次提交,提交及之前的commit都会被保留,但是此次之后的修改都会被退回到暂存区
1.1.回退
$ git reset--hard HEAD^ 回退到上个版本
$ git reset --hard HEAD~3 回退到前3次提交之前,以此类推,回退到n次提交之前
$ git reset --hard commit_id 退到/进到 指定commit的sha码
1.2.强制推送远程
$ git push origin HEAD --force
如果使用这个方法失效了,提示 :不允许强制将代码推送到此项目上受保护的分支
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
2.git revert
生成一个新的提交来撤销某次提交,此次提交之前的commit都会被保留
2.1.回退
$ git revert commit_id 退到/进到 指定commit的hash码
2.2.强制推送远程
$ git push origin --force