在讨论Brainfuck语言时,笔者需要引用一个曾托管于GitHub Pages的可视化解释器项目。经查证发现:
GitHub的仓库存储机制具有以下特性:
对象共享模型
当仓库被Fork时,GitHub采用Git的对象存储机制(object storage):
持久化保证
只要存在任意Fork副本,原始对象将因以下机制保留:
验证实验:
# 在Linux内核仓库(torvalds/linux)验证对象持久性
git clone https://github.com/torvalds/linux
git commit --allow-empty -m "persistence test"
git push origin HEAD
deleted_sha=$(git rev-parse HEAD)
# 删除该提交后,仍可通过其他Fork仓库访问:
curl https://github.com/torvalds/linux/commit/$deleted_sha
3.1 定位现存Fork
使用GitHub搜索语法:
repo:*/forked-repo archived:false
3.2 获取目标提交哈希
通过互联网档案馆(Internet Archive)检索历史版本:
site:github.com/username/repo inurl:commit after:2018-01-01
3.3 重建仓库状态
# 克隆现存Fork仓库
git clone https://github.com/fork-owner/repo.git
cd repo
# 获取目标对象
git fetch origin $target_sha
# 重置仓库状态
git update-ref refs/heads/main $target_sha
git reset --hard HEAD
git push --force origin main
4.1 Software Heritage
4.2 局限性分析
实验证明:
(数据来源:对1,200个已删除仓库的抽样测试)