Skip to content

Instantly share code, notes, and snippets.

@altphi
Last active May 4, 2017 19:29
Show Gist options
  • Save altphi/00463687f86e8bf7f1a80de7570ec3c7 to your computer and use it in GitHub Desktop.
Save altphi/00463687f86e8bf7f1a80de7570ec3c7 to your computer and use it in GitHub Desktop.
Clear all whitespace-only-changes from files in a git repository.
#!/usr/bin/env sh
# leaves a backup of all changes in git stash, creates a patch ignoring whitespace changes, clears changes, applies patch
cd "$(git rev-parse --show-toplevel)"
git stash && git stash apply && git diff -w > changes.patch && git checkout . && git apply --whitespace=fix changes.patch && rm changes.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment