reset 和 revert
git reset
在 Gitee 上新增仓库 git-demo,并 clone 到本地
bash
git clone https://gitee.com/newarea0/git-demo.git
通过 VSCode 打开项目
新增文件 README.md
3次编辑 README.md
,每次都提交更改,并同步到远程仓库 Gitee

Preview

Preview
现在要回退到之前版本,如 主要组成

Preview
bash
git reset --hard 731473
或者通过 VSCode 操作

Preview

Preview
Reset 更改保留在本地
Soft Reset 更改保留在暂存区
Hard Reset 丢弃更改
回退后:

Preview
同步到远程
此时本地库HEAD指向的版本比远程库的要旧,使用 git push
会报错

Preview
改用使用 git push -f
强制推上去

Preview
git revert
我们commit了三个版本(版本一、版本二、 版本三),突然发现版本二不行(如:有bug),想要撤销版本二,但又不想影响撤销版本三的提交,就可以用 git revert 命令来反做版本二,生成新的版本四,这个版本四里会保留版本三的东西,但撤销了版本二的东西。