post icon

Completely remove a file or directory from all revisions in a git repository

I’ve accidentally added files and directories into my git repository before and forgot that I did. Then a few days later was swearing and cursing. After a pile of google searching I’ve found a couple resolutions for these problems that have and are working perfect for me.

First I take no responsibility for your actions on performing these commands. I’m not positive if you can undo these changes. You will want to maybe back up your files before trying these out.

Remove Directories

git filter-branch --tree-filter 'rm -rf vendor/plugins/someshitplugin' HEAD

Remove Files

git filter-branch -f --index-filter 'git update-index --remove public/index.html' HEAD

Then after either of those run these two commands:

git push --force --verbose --dry-run
git push --force

No comments yet.

Leave a comment