参考文档:Git使用教程 - 简书
git reset HEAD~
git reset --mixed HEAD~


git reset --soft HEAD~


git reset --hard HEAD~


默认选项
git reset HEAD~ 等效于 git reset --mixed HEAD~ ,影响了两棵树:首先是移动 HEAD 的指向,将其指向上一个快照(HEAD~),然后再将该位置的快照回滚到暂存区域。
--soft选项
git reset --soft HEAD~ 命令就相当于只移动 HEAD 的指向,但并不会将快照回滚到暂存区域。相当于撤消了上一次的提交(commit)。一不小心提交了,后悔了,那么你就执行 git reset --soft HEAD~ 命令即可(此时执行 git log 命令,也不会再看到已经撤消了的那个提交)。
--hard选项
reset 不仅移动 HEAD 的指向,将快照回滚动到暂存区域,它还将暂存区域的文件还原到工作目录。
网友评论