At work I'm coding in C# using Visual Studio and Resharper, which liberally change whitespace, including breaking lines, even of code I'm not editing.
This is fine for new code I'm writing, or even old code I'm editing, but for old code I'm not touching, it results in a lot of cruft in the git diffs.
The workflow process I usually follow is to create a new branch, and do my changes there, and push when it's ready for review.
But before I push, I'd like to clear out all the changes that are solely whitespace changes. i.e. lines being split like so:
a + b + c
to
a +
b +
c
and all sorts of other whitespace changes that don't change the behaviour of C# code as it doesn't give meaning to whitespace.
Of course I don't want to stop any whitespace changes, obviously between commits I might change the whitespace of new code.
But it's the code I haven't touched in my branch that I want any whitespace changes removed from.
I just want to make a commit, before the final push, that rolls back all changes that are whitespace only as compared to the point the initial branch was taken.
Is there a way to do this or a nice way to script it?
I attempted this with the following script:
#!/bin/bash
BRANCH_BASE=$(git merge-base --fork-point origin/dev)
git diff $BRANCH_BASE HEAD -w --word-diff-regex=[^[:space:]] > /tmp/no_whitespace_changes.patch
git checkout $BRANCH_BASE
git apply /tmp/no_whitespace_changes.patch
My intent was to then rebase on top of the branch head, but I get a fatal: corrupt patch at line 6
error upon running this, so I'm obviously doing something hideously wrong.
But perhaps there's a better way anyway to solve this. I feel like others would have this same problem so I don't want to reinvent the wheel.