掌握 Git 高级特性,提升工作效率
Reflog - 引用日志
理解 Reflog
Reflog 记录了 HEAD 和分支引用的所有变化历史,是恢复"丢失"数据的救命工具。
# 查看 HEAD 的 reflog
git reflog
git reflog show HEAD
# 查看特定分支的 reflog
git reflog show main
# 详细格式
git reflog --date=iso
# 输出示例:
# abc1234 HEAD@{0}: commit: Add feature
# def5678 HEAD@{1}: checkout: moving from main to feature
# ghi9012 HEAD@{2}: commit: Fix bug
# jkl3456 HEAD@{3}: rebase finished: returning to refs/heads/main
2026/3/20大约 11 分钟