Skip to content

Instantly share code, notes, and snippets.

@francois
Created December 27, 2013 20:04
Show Gist options
  • Save francois/8151926 to your computer and use it in GitHub Desktop.
Save francois/8151926 to your computer and use it in GitHub Desktop.
Simple git pre-commit hook to prevent trailing whitespace from entering the repository.
#!/bin/sh
if ( /usr/bin/grep --quiet --exclude="*.log" --recursive --extended-regexp ' $' * )
then
echo >&2 "Trailing whitespace errors found in:"
/usr/bin/grep >&2 --files-with-matches --exclude="*.log" --recursive --extended-regexp ' $' *
echo >&2 ""
echo >&2 "Please fix before trying to commit again"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment