22

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.

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.

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?

noone
  • 321
  • 1
  • 2
  • 3
  • For security purposes, if this file were to contain any sensible information such as passwords, I advise you to immediately change them. – HeroicKatora Jul 30 '17 at 18:34
  • Possible duplicate of [Remove sensitive files and their commits from Git history](https://stackoverflow.com/questions/872565/remove-sensitive-files-and-their-commits-from-git-history) – phd Jul 30 '17 at 18:41
  • No, it doesnt contain any sensitive informations, but still I would like to delete it. – noone Jul 30 '17 at 18:44
  • 1
    See the answer from Github: https://stackoverflow.com/a/34594815/7976758 – phd Jul 30 '17 at 21:48

2 Answers2

23

This has worked for me:

I have reset the head to the number of commits back by 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.

nj2237
  • 1,220
  • 3
  • 21
  • 25
  • 5
    This removes the commit from the branch but does not completely delete the commit and it would still visible on github.com. The url for the commit would be https://github.com/user-name/my-repo/commit/abcdef0 where abcdef0 is the commit hash (shortversion). – Robino Apr 29 '22 at 13:42
17

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.

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 not be anymore available through its SHA1 URL.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250