Skip to content

Instantly share code, notes, and snippets.

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