in Git

Remove file from git history

During a careless commit to my git repository I managed to push a database dump file before realising my mistake. Even though I removed the file and pushed the new version the file still existed in the repository history making it very large for re-downloading or for any new cloning.

Here is what I found. To remove the file you need to rewrite the repository history and remove the reference to the offending file.

git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch db_dump.sql" -- --all
Thanks to Drew

Then all I had to do was push the local repository back up.
git push --force origin --all

Write a Comment