Git rewrite history by running an external tool for each commit

We have a repo with several thousand commits that use the really old code convention that we want to replace with standard Microsoft. The easiest way is to run the code formatting tool only for the last commit, but this way we lose the “guilt” and the story becomes harder to follow. Is it possible to do this by running the code formatting tool (in our case https://github.com/dotnet/codeformatter ) at each commit, while maintaining the change history and which version of the filter branch should be used?

Edit: it turns out that the tool that I was going to use broke into some of the commits, so why the filter branch did not work for me and did not apply any changes to the commits

+5
source share
2 answers

You can do this with a tree filter:

git filter-branch --tree-filter "CodeFormatter.exe" 
+3
source
 git rebase --interactive --exec CodeFormatter.exe --root 

those. perform interactive reboot the execution of this command with each commit .

Shorten the team to

 git rebase -i -x CodeFormatter.exe --root 
+1
source

Source: https://habr.com/ru/post/1275332/


All Articles