其他分享
首页 > 其他分享> > git删除已经提交但未推送的更改

git删除已经提交但未推送的更改

作者:互联网

1.

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

 

注意:reset重置的意思,即重置到提交是commit ID的地方,所以要删除当前的提交,需要将commit ID设成上一个提交id,即要还原到的最后一个提交
————————————————
版权声明:本文为CSDN博主「酸菜鱼和青椒鱼我都可以」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u013986317/article/details/107106702

2.

1、首先 stash当前的代码
2、在本地项目的地方鼠标右键 选择 Git Bash Here 然后执行git reset HEAD^n,n为需要取消的commit次数

标签:reset,git,更改,--,撤销,提交,commit,推送
来源: https://www.cnblogs.com/wangfei-xsy/p/16450231.html