git 如何从 GitHub 完全删除提交?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45403222/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:50:30  来源:igfitidea点击:

How to completely delete a commit from GitHub?

gitgithub

提问by noone

On GitHub, I forked a repositary and cloned on my PC. Then, for testing purpose, I edited a file, made a commit and pushed it to GitHub. But now I would like to completely delete this commit.

在 GitHub 上,我创建了一个存储库并克隆到我的 PC 上。然后,出于测试目的,我编辑了一个文件,进行了提交并将其推送到 GitHub。但现在我想完全删除这个提交。

I did the following:

我做了以下事情:

git reset --hard <sha1_of_previous_commit>
git push --force

It looked OK, but my commit was still accessible on GitHub by URL with SHA1 of my commit. So I deleted the repositary on GitHub, then the URL was saying Not Found.

看起来不错,但是我的提交仍然可以在 GitHub 上通过带有 SHA1 提交的 URL 访问。所以我删除了 GitHub 上的存储库,然后 URL 显示未找到。

But if I fork the same repositary again, my commit is again accessible by this URL. Please help me, how the hell I can get rid of this commit?

但是如果我再次 fork 同一个存储库,我的提交可以再次通过这个 URL 访问。请帮帮我,我怎么能摆脱这个提交?

回答by nj2237

This has worked for me:

这对我有用:

I have reset the head to the number of commits back by 2

我已将头部重置为 2 的提交次数

git reset --hard HEAD~2

and force pushed my branch to remote by

并强制将我的分支推到远程

git push -f origin my_branch_name

I could not see any traces of the commits on remote repo.

我在远程仓库上看不到任何提交的痕迹。

回答by VonC

The "Removing sensitive data from a repository" is quite clear on that:

从存储库中删除敏感数据”对此非常清楚:

it's important to note that those commits may still be accessible in any clones or forks of your repository, directly via their SHA-1 hashes in cached views on GitHub, and through any pull requests that reference them.
You can't do anything about existing clones or forks of your repository, but you can permanently remove all of your repository's cached views and pull requests on GitHub by contacting GitHub Support.

重要的是要注意,这些提交仍然可以在存储库的任何克隆或分支中访问,直接通过 GitHub 上缓存视图中的 SHA-1 哈希值,以及通过引用它们的任何拉取请求。
您无法对存储库的现有克隆或分支执行任何操作,但您可以通过联系 GitHub 支持永久删除存储库的所有缓存视图和 GitHub 上的拉取请求。

In your case, there was (hopefully) no fork/clone, but you have to contact GitHub support to request a gc on their version of the repo, in order for the commit to notbe anymore available through its SHA1 URL.

在你的情况,有(希望)无叉/克隆,但是你必须联系GitHub的支持,要求对他们的版本回购的GC,为了使承诺成为了可通过其SHA1 URL。

回答by Harald Nordgren

It's possible that the commit will always be accessible through the URL. But it's not shown on Github, so I don't see how this is a problem unless it contains sensitive information.

有可能始终可以通过 URL 访问提交。但它没有显示在 Github 上,所以除非它包含敏感信息,否则我看不出这是一个问题。

Subsequent commits will have unique hashes.

后续提交将具有唯一的哈希值。