The commit has not been pushed yet, and the commit method is revoked

What should I do if I want to undo the commit after executing the commit but before executing the push?

Solution:
use the command:

Only undo the last commit, not add

git reset --soft HEAD^

 Both commit and add were revoked last time

git reset --hard HEAD^

HEAD^ indicates the previous version, that is, the last commit, and can also be written as HEAD~1.
If you want to withdraw both commits, you can use HEAD~2

–soft
does not delete the changed code in the workspace, undoes the commit, does not undo the git add file

–hard
deletes the changed code in the workspace, undoes the commit and undoes the add

Another point, if the commit comment is wrongly written, you need to change the comment first, and there are other ways to achieve it, such as:

git commit --amend
这时候会进入vim编辑器,修改完成你要的注释后保存即可。

Guess you like

Origin blog.csdn.net/lian740930980/article/details/126582924