git 如何撤销 commit (未 push) git 如何撤销 commit (未 push)

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

1 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,删除编辑器改动代码

如果嫌输出信息太多,可加上--pretty=oneline参数,即 

1 git log --pretty=oneline