I'd like to run an auto-formatting tool (e.g. Prettier, go fmt, clang-format, terraform fmt ...) on all commits in a branch. I could manually edit each commit in the branch using an interactive rebase (git rebase -i) but that is quite tedious if there are a lot of commits on the branch.
How do I automatically apply the auto-formatting to each commit in the branch?
You can use
git rebase --execlike so:Source: https://blog.scottlogic.com/2019/03/04/retroactively-applying-prettier-to-existing-branches.html
Note: This is also possible using
git filter-branch --tree-filterbut that command is now discouraged and produces a warning when invoked on the command-line. The suggested alternative git-repo-filter cannot do this directly, but contains an examplelint-history-command which is able to do this.