遇到commit提交多了东西,想取消。
git的取消commit
git的取消commit
在HEAD后面加~1等数字。

具体说明:

修改了本地的代码,然后使用:

git add file
git commit -m ‘修改原因’

执行commit后,还没执行push时,想要撤销这次的commit,该怎么办?

解决方案:
使用命令:

git reset --soft HEAD^

这样就成功撤销了commit,如果想要连着add也撤销的话,–soft改为–hard(删除工作空间的改动代码)。

命令详解:

HEAD^ 表示上一个版本,即上一次的commit,也可以写成HEAD~1
如果进行两次的commit,想要都撤回,可以使用HEAD~2

–soft
不删除工作空间的改动代码 ,撤销commit,不撤销git add file

–hard
删除工作空间的改动代码,撤销commit且撤销add

相关文章:

  • 2021-07-15
  • 2021-03-31
  • 2022-02-06
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2021-08-18
猜你喜欢
  • 2021-09-19
  • 2021-09-27
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
相关资源
相似解决方案