How to run unexpand in all the changed lines in a series of git commits?

Viewed 41

I have a series of git commits that, due to different editor defaults, ended up with huge whitespace diffs around every line that I ever touched. This makes git merges significantly harder, and violate the coding standards of the project I want to eventually upstream the changes to.

It's too many to fix manually, so I wanted to use unexpand.

However, I cannot just get a list of all the changed files in every commit and run unexpand on them, as some contain embedded tabs and I also cannot make whitespace modifications to lines I do not modify.

But, I also cannot run unexpand on the new files I add in the commits, as that would disrupt git history (long story).

So, what command/script should I use to run unexpand on all modified lines (but not touch added files) on a series of git commits?

1 Answers

git diff has a set of options to ignore whitespaces under some condition.

git format-patch can generate a list of patches, taking into account such options, and tuned to be usable by git am.

So you can try something along the lines of :

git switch -c wip <base_commit>
git format-patch -o ../mypatches --ignore-space-change HEAD..mybranch
git am ../mypatches/*

The difficulty will come from applying patches where the spacing does not match the content of your files on disk; if the number of commits to replay is small, this may still be manageable.

Related