操作系统原理 2026

reflog 与持久化对象

原片 00:55:02—00:56:02

这当然可以。2015 年,为 multi-tasking,git 增加 worktree。persistent data structure 保留历史,先看一个例子。

图 46:对象内容显示 merge commit 的两个 parent(00:55:19)。
图 46:对象内容显示 merge commit 的两个 parent(00:55:19)。

merge commit 在对象内容中记录的两个 parent:

parent 755ebd91c1a5bd7a1eee906013f65fc6036ddeb3
parent 531edd8e67359bedc84adfa2e5c6f9c6a83d2cac

Merge branch 'newnew' into new

git reflog 会记录历史。git reset --hard 后,未 add 的内容会丢,但其他对象因为已经持久化,还在文件系统。只要不 git gc,即便 commit 已无引用,或者引用关系弄坏,对象仍可能恢复。

图 47:reflog 记录 HEAD 的移动(00:55:36)。
图 47:reflog 记录 HEAD 的移动(00:55:36)。

tree object、blob object 仍在,都可能恢复。git reflog 能帮助找回历史,这正是 persistent data structure 带来的能力。

输入关键词,搜索全部 30 节课。