Cleaning up whitespace changes in a pull request

Recently a core committer requested me to remove whitespace changes (blame my idea settings that formatted tab spacing etc). Here’s an easy way to do this –

  • soft reset the commit on your local branch
1
git reset --soft HEAD~1
  • create a patch using git-diff requesting it to ignore space changes
1
git diff --ignore-all-space --ignore-blank-lines > ../commit.patch
  • verify and apply the patch (use patch or git-apply)
1
2
patch --ignore-whitespace --dry-run ../commit.patch
patch --ignore-whitespace ../commit.patch
  • short alternative
1
git diff --ignore-all-space --ignore-blank-lines | git apply --reject --cached --ignore-space-change
  • manually fix whitespace issues where code changes were made
  • force push commit to branch which was used to create the pull request
  • suggest using a common code style for the repository