Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git remove files from repository, Github and commiters

Somebody accidentally checked in 80 megs worth of JPG's into our git repository and pushed it to github central repository.

A few people since pulled these changes.

Apart from shooting the committer, what can I do to remove these images completely from the repository's history and github? And then inflict all changes on other committers.

like image 886
iBiryukov Avatar asked Apr 30 '26 17:04

iBiryukov


2 Answers

You need to fix the changes with git reset sha_of_last_good_commit than push those backup up with git push -f. You will than need to tell everyone to pull the new changes back down.

  • If there are changes that you want to keep intermingled with the bad commits, you will need to git rebase -i to pluck out the ones you don't want before you push your fixed repo back up to github.

  • Garbage collection will eventually remove the dangling objects, or you can force it with git gc --aggressive

like image 138
Andy Avatar answered May 03 '26 06:05

Andy


A more radical approach is using filter-branch.

git filter-branch --tree-filter 'rm -f *.jpg' HEAD

However you should be VERY careful when using this, as you can really mess up your repo. You should check the docs before doing anything.

like image 45
Mario F Avatar answered May 03 '26 08:05

Mario F



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!