Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a blob from a Git repo

I accidentally added a database dump (over 1 GB) to my repository, pushed it and noticed this few days later.

I used git filter-branch to delete the file, expired reflog and ran git gc to prune unused objects, but the database dump blob is still in the repository. I used Which commit has this blob?, but I did find any commit which has a reference to the blob. How can I delete this or how do I find out why it didn't get deleted during git gc?

like image 200
Maciej Lotkowski Avatar asked Aug 26 '11 08:08

Maciej Lotkowski


2 Answers

Which command did you call exactly when running git gc?

Note the manpage of git gc:

The optional configuration variable gc.pruneExpire controls how old the unreferenced loose objects have to be before they are pruned. The default is "2 weeks ago"

So if your blob is younger than 14 days, you have to call

git gc --prune=<date> (for date you also can insert now)
like image 116
dunni Avatar answered Sep 20 '22 09:09

dunni


Just do rm .git/objects/path/to/blob.

I am not sure why git-gc didn't delete it.

like image 21
Chaitanya Gupta Avatar answered Sep 19 '22 09:09

Chaitanya Gupta