git filter-branch --tree-filter <command> -- --all
This allows you to edit the contents of the tree (the actual files and directories) for each commit.
It will run a command in a directory containing the entire tree, your command may edit files, add new files, delete files, move them, and so on. Git will then create a new commit object with all of the same metadata (commit message, date, and so on) as the previous one,