–soft: 之前的修改保留在暂存区.
–mixed (default): 之间的修改保留在工作区
–hard: 之前的修改直接丢掉
举例
准备工作
首先我们先做一下准备工作:新增两条记录
新建 1.txt 文件,并提交到本地仓库。
git init
touch 1.txt && echo 'Hello,world' > 1.txt
git add .
git commit -m'新增 1.txt'
新建 2.txt 文件,并提交到本地仓库
touch 2.txt && echo "Hello,world2" > 2.txt
git add .
git commit -m'新增 2.txt'
效果如图
现在假设我们想要回滚第二条 log 即‘新增 2.txt’ ,接下来我会演示这三种回滚后的区别。
--soft
git reset --soft 9506042eb07d
git status
--mixed(默认)
git reset --mixed 9506042eb07d
git status
--hard
git reset --hard 9506042eb07d
git status
如果使用 vscode 自带的git 管理插件,效果看起来会更直观。