Git撤销已经提交的 commit

Git撤销已经提交的 commit

在进行 git commit -m "提交信息"的操作后,想取消commit的操作,怎么办?

这个时候需要使用 git reset,即重置操作,根据重置的程度不同,可分为以下三种:

--mixed

git reset --mixed commitId

--mixed 保留 本地仓库暂存区、以及工作区的代码,即回到 git add . 操作之前的状态

注意 : commitId 通过 git log 可以查看到 commit的历史 获得,如下图所示:

image-20200915135333842

--soft

git reset --soft commintId

--soft 保留 暂存区工作区的代码,即回到 git commit -m "提交信息" 操作之前、 git add . 操作之后 的状态

前两种在开发中普遍使用。

--hard

git reset --hard commitId

--hard 不会保留提交的代码,即会造成commit的代码以及工作区的代码丢失,一朝回到解放前,慎用!慎用!慎用!

博客参考文章:https://www.cnblogs.com/panbingwen/p/10736938.html

自我控制是最强者的本能-萧伯纳
原文地址:https://www.cnblogs.com/CF1314/p/13672777.html