📖 Git 撤销与回退速查

按使用场景分组,点击"复制"按钮一键复制命令

撤销未提交的改动
丢弃某个文件的工作区修改 ⚠️
git restore <file>
丢弃全部工作区改动 ⚠️
git restore .
取消暂存(改动保留在工作区)
git restore --staged <file>
撤销已提交的改动
生成反向提交(安全,推荐用于已推送的提交)
git revert <commit>
回退到指定提交,改动保留在工作区
git reset --soft <commit>
回退并彻底丢弃改动 ⚠️
git reset --hard <commit>
修改最近一次提交(追加文件或改信息)
git commit --amend
找回与挽救
查看引用日志(找回误删的提交 / 分支)
git reflog
从 reflog 中的提交恢复分支
git branch <name> <commit>
临时保存现场
git stash
查看暂存列表
git stash list
恢复最近一次暂存并删除记录
git stash pop