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
git reset --soft HEAD~1
  • create a patch using git-diff requesting it to ignore space changes
git diff --ignore-all-space --ignore-blank-lines > ../commit.patch
  • verify and apply the patch (use patch or git-apply)
patch --ignore-whitespace --dry-run ../commit.patch
patch --ignore-whitespace ../commit.patch
  • short alternative
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