用 git reflog 找回丢失的提交
在误重置、误变基或误删分支后找到并恢复提交。
运行 git reflog 列出最近的 HEAD 位置,再 reset 或 cherry-pick 需要的提交。
01命令
命令
$ git reflog02作用说明
reflog 是每次引用移动的本地日志,包括已不再被任何分支引用的提交。它是命令行历史编辑的安全网,图形界面无法像它一样恢复游离或已丢弃的提交。
03风险
!注意: reflog 条目会在默认保留期后过期;请尽快恢复并把 SHA 另存。
04撤销
撤销
$ git reset --hard HEAD@{1}05来源
- git-reflog documentation依据: Documents the reflog, which records where HEAD and branches have pointed.
最后验证: 2026-10-13 · 分类: 开发者