We have a repo with several thousands of commits that uses a really old code convention we want to replace with the default Microsoft one. The easiest is to run a code formatting tool on the latest commit only, but this way we lose "blame" and the history gets harder to follow. Can this be achieved by running the code formatting tool (in our case https://github.com/dotnet/codeformatter) on each commit, thus preserving change history, and what version of filter-branch should we use?
Edit: turns out the tool I was about to use was crashing on some of the commits, so that's why filter-branch did not work for me and did not apply any changes to the commits
You can do this with the tree filter:
git filter-branch --tree-filter "CodeFormatter.exe"
git rebase --interactive --exec CodeFormatter.exe --root
I.e. perform an interactive rebase executing the given command on every commit.
Shorten the command to just
git rebase -i -x CodeFormatter.exe --root
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With