如何撤销 Git commit ?

准备提代码,已经git add . 了,也已经Git commit -m 'xxx'  了,发现代码有问题,于是想撤回commit ,怎么办?


撤销commit一般用git reset ,语法如下:

git reset [ --mixed | --soft | --hard] [<commit ID>]

1.使用参数--mixed(默认参数),如git reset --mixed <commit ID>或git reset <commit ID>

撤销git commit,撤销git add,保留编辑器改动代码

2.使用参数--soft,如git reset --soft<commit ID>

撤销git commit,不撤销git add,保留编辑器改动代码

3.使用参数--hard,如git reset --hard <commit ID>——此方式非常暴力,全部撤销,慎用

撤销git commit,撤销git add,删除编辑器改动代码

原文地址:https://www.cnblogs.com/fxwoniu/p/13361678.html