背景
因某种原因,想要撤销远程commit。

这是仓库中最新的一个commit 70941794bacd1803389165d06a1b7fdf81b071af,我想提交新的commit覆盖它。
1.查看本地commit
git log

2.本地分支回退
git reset --soft 602d6f8a353ada4cb760351dbd4451b8e9c18386//保留工作区内容 --hard则不保留

3.撤销远程commit
git push --force
查看仓库commit记录

可以看到之前的commit被撤销了。
撤销可以理解为:本地回退到之前的commit,force强制push使远程跟本地同步。
注意:如果分支是多人协作,千万不要使用这种方式,因为别人提交到服务器的代码很有可能被你撤销了,如果分支你一个人玩则无所谓。
资料
https://blog.csdn.net/qq_33358062/article/details/84854446
https://docs.github.com/en/free-pro-team@latest/github/committing-changes-to-your-project/changing-a-commit-message
网友评论