How to remove whitespace-only changes from a PR
-
Create a new local branch that will contain your changes without the whitespace
git checkout -b tmp-branch
-
Merge the changes that contain whitespace into your current branch WITHOUT committing the changes
git merge --no-commit
-
Create a diff that ignores whitespace and apply it to your branch. This creates a diff in unified format, ignoring whitespace, and not colorizing the output. Then using git to apply (like applying a patch) to the current directory.
git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero -
-
Remove any remaining unstaged changes. The unstaged changes are the whitespace-only changes
git checkout .
-
Add any new files back to the staged changes since the diff/apply method ignores net-new files.
git add .
-
Verify your work
git diff --cached
-
Commit your work!
git commit
Thanks Josh for this tutorial!
This worked for me: