Another post about erasing files/directories from git history

~ brew install git-filter-repo
~ git filter-repo --invert-paths --path 'path-to-file-or-directory'
~ git remote remove origin
~ git remote add origin git@github.com:<path-to-repository>.git
~ git push origin --force 'refs/heads/*'
Note that I'm using brew
to install git-filter-repo, you may need to look for alternative installation methods, depending on your OS.
The filter-repo
command is actually filtering all files except (--invert-paths
) the ones that match the --path
parameter - check out the user manual for more info.
Once this is done, you need to rebase the other branches:
~ git checkout other-branch
~ git rebase main
If you want to make sure you didn't break anything, create a new branch and publish the changes:
~ git checkout -b other-branch-rebase-test
~ git push --set-upstream origin other-branch-rebase-test
If everything looks good, you can finalize the rebase:
~ git checkout other-branch
~ git push --force
Note that if you host your repositories on Github, these commits will not be removed, instead they will still be available but not linked with any specific branch.