Skip to content

Instantly share code, notes, and snippets.

@lwalen
Created February 2, 2016 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lwalen/d882b225850575eca9f7 to your computer and use it in GitHub Desktop.
Save lwalen/d882b225850575eca9f7 to your computer and use it in GitHub Desktop.
Removes trailing whitespace from modified lines
#!/bin/bash
git diff --cached --no-color > stage.diff && \
git apply --index -R stage.diff && \
git apply --index --whitespace=fix stage.diff &> log.txt && \
removals=$(egrep -v '(stage.diff:|warning:)' log.txt | wc -l | tr -d '[[:space:]]') && \
echo "whitespace removed from $removals line$([ $removals -ne 1 ] && echo 's')" && \
rm -f stage.diff log.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment