永久删除提交

Remove commit for good

我知道这个问题有成千上万的讨论帖。

但是我发现了一件非常奇怪的事情。

如果您在 GitHub 上创建项目,请进行一些提交。
假设提交 1、2、3、4、5。
后来,您意识到要将某些内容更改为提交 3。

因为你在自己的分支工作,所以改写历史没有问题。

所以让我们这样做:(基于 this Whosebug 答案)

git rebase --interactive 'bbc643cd^'

// Modify 'pick' to 'edit' into interactive prompt and :
git commit --all --amend --no-edit
git rebase --continue
git push -f

太棒了!错误已更正。 历史已被重写,所以提交 bbc643cd 现在是 lkqjfhchc.
您可以在 GitHub 上查看来源,所有内容都已更新。

但仍然有人可以在 GitHub 上找到它!

访问 URL:https://github.com/your-nickname/your-project/commit/bbc643cd...(完整提交哈希),您会找到它!

我们如何才能永久删除此提交?

感谢您的帮助!

根据您的补充意见:

你所做的一切都是应该的。
重点是:git 永远不会丢失数据,除非你告诉它(所谓的 gc - 垃圾收集器)

文件将保留在那里,直到调用 gc。

这叫做dangling file

Dangling commit

A commit that isn't linked to any branch or tag either directly or by any of its ascendants.

你可以在本地看到所有悬空引用:

git fsck --full

摆脱它的唯一方法是 运行 gc

## !!!Caution:
## It will remove all your dangling files
git gc --aggressive --prune=now

你可以阅读更多相关内容。

我从这里联系了 Github 工作人员:https://github.com/contact

这是答案(我对此无能为力,没有修剪,没有 gc 等)

Hey Maxime,

The commit was available because commits are not automatically deleted when they're removed from the history of a branch -- they're deleted when they're garbage collected. I just ran garbage collection for that repository manually and the commit should now return a 404.

How often does the garbage collector run on your end?

GitHub 没有计划的垃圾回收进程。我们不 自动清除存储库缓存(我们在版本控制中 业务,所以除非绝对必要,否则我们不会删除数据)所以 通常,我们这样做的唯一原因是如果有人 写作 要求我们将它们作为敏感数据的一部分清除 删除过程.

我们也可能出于技术原因清除缓存,如果 回购协议的内容或结构给我们带来了困难 托管它,但这通常只有在回购是 特别大或具有结构复杂的文件夹布局。

如果您对此有任何疑问或任何问题,请告诉我 否则。

希望对您有所帮助。

干杯,XXXXX

所以你只需要等待或联系工作人员强制垃圾收集器,以防你遇到同样的问题!