git reflog 记录您的分支 HEAD 曾经在哪里——每个 commit、checkout、reset、rebase 等。这是一个安全网,用于恢复"丢失的"提交(在执行错误的 reset、rebase 或删除分支后),这些提交看似消失了,但仍然是可恢复的。
reflog 是什么
The REFLOG logs every movement of HEAD (and branch tips) in YOUR local repo:
→ every commit, checkout, reset, rebase, merge, etc. is recorded with a reference
→ it's LOCAL and includes commits not reachable from any branch (the "lost" ones)
→ Even if you reset/rebase away commits, reflog remembers where they were.
恢复丢失的工作
git reflog
git checkout def456
git branch recovered def456
git reset --hard def456
