git撤销commit-hard

时间:2023-03-09 17:18:29
git撤销commit-hard

场景:

不小心commit了一个不应该commit的修改,但是还没有push,想撤销那个commit

命令:

a)git log

b)git reset --hard commit_id

具体步骤如下:

1.模拟commit一个不应该commit的修改:

1.1.原来的list.view.js文件

git撤销commit-hard

1.2.原来的待push列表

git撤销commit-hard

1.3.按以下方法修改list.view.js文件

git撤销commit-hard

1.4.commit后的待push列表

git撤销commit-hard

2.打开git bash,并转到对应目录

git撤销commit-hard

3.执行命令:git log

记录由上至下出现的第二个commit_id(d1a65e9ac9a7c4396206f0072b7fbc9138a26c1f)

git撤销commit-hard

4.执行命令:git reset --hard commit_id

即:git reset --hard d1a65e9ac9a7c4396206f0072b7fbc9138a26c1f

git撤销commit-hard

5.再查看list.view.js和待push列表,即回到1.1和1.2的状态