Skip to content

Instantly share code, notes, and snippets.

@lwalen
Created February 2, 2016 01:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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