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