42

Yesterday, I pushed to my fork of ConnectBot on GitHub. I pushed once, realized that I hadn't made the change the way I wanted, redid the commit and pushed again.

Now, GitHub has both commits:

My master branch is only tracking the second commit, but the first commit is still available and is still in my activity feed. How can I remove it to make sure no one accidentally pulls that commit instead of the corrected version?

Palec
  • 12,743
  • 8
  • 69
  • 138
We Are All Monica
  • 13,000
  • 8
  • 46
  • 72

2 Answers2

13

Delete the repo or contact GitHub

Deleting the repo and recreating it without the bad commit seems to work if you can afford losing all issues. The data also disappears from the commit API (although push events are still visible). See also: https://stackoverflow.com/a/32840254/895245

If you can't afford to lose issue data, GitHub support can manually delete dangling commits. For example, when I uploaded all GitHub commit emails to a repo they asked me to take it down, so I did, and they did a gc. Pull requests that contain the data have to be deleted however: that repo data remained accessible up to one year after initial takedown due to this.

Their current help page says:

you can permanently remove all of your repository's cached views and pull requests on GitHub by contacting GitHub Support.

Maybe making the repo private will also keep the issues around and get rid of the commit, I'm not sure. You lose starts/forks for sure though. Not sure if after restore the commits will be gone or not. But at least you might be able to keep a private backup of issues.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
12

If you really need it to be removed immediately, you would probably have to contact GitHub Support.

Pulling should generate a pack that contains only objects that are referenced so no one should get that commit as a result of a clone or a pull. For example,

$ git clone git://github.com/nylen/connectbot.git
Cloning into connectbot...
remote: Counting objects: 6261, done.
remote: Compressing objects: 100% (1900/1900), done.
remote: Total 6261 (delta 3739), reused 5980 (delta 3520)
Receiving objects: 100% (6261/6261), 3.04 MiB | 3.40 MiB/s, done.
Resolving deltas: 100% (3739/3739), done.
$ git cat-file -t 1cd775d
fatal: Not a valid object name 1cd775d
Rus
  • 47
  • 10
Emil Sit
  • 22,894
  • 7
  • 53
  • 75
  • 36
    After four years, both OP's commits are still available on Github. – Raf Jul 29 '14 at 09:23
  • The old commit is still available by SHA, but it doesn't show up in the commit list. – Quantum7 Jan 28 '15 at 15:56
  • I'd be interested in whether it would show up elsewhere after all this time. For instance, do old commits which reference issues show up in the issue view forever? – Quantum7 Jan 28 '15 at 15:57
  • 21
    What's the basis for you saying that github will periodically garbage collect commits that aren't referenced? I've heard this said before but can't find anything more credible than answers like this. – Ernest Apr 23 '15 at 20:04
  • 1
    @Quantum7, Atlassian has a nice article on when gc is run. As I understand it, any git repo will check itself during a push and if things are 'too big' , gc will run. Secondly, FYI, I ran git gc and my dangling commits were not removed. – AnneTheAgile Jan 05 '16 at 19:10
  • 6
    You need to contact GitHub support (as [indicated here](https://help.github.com/articles/remove-sensitive-data/)) to remove cached commits which are no longer referenced. – Jonathan Cross Nov 15 '16 at 21:14
  • 6
    In my case, I contacted github and they replied back that said they "cleared the cache on our end and run garbage collection" and I was able to confirm that the commits were no longer accessible. – haridsv Aug 03 '17 at 11:13
  • @Quantum7 Jira can find this dangling commits referencing tickets so they probably will show up there forever – Andrey Semakin Nov 13 '19 at 11:04
  • 14
    11 years now and OP's dangling commit is still available on Github ( `1cd775d` ) – andreiashu Apr 09 '21 at 02:37
  • After 12.5 years it's STILL there... – SuperScienceGrl Jul 01 '23 at 08:42