Skip to content

Instantly share code, notes, and snippets.

@rohenaz
Last active April 3, 2019 15:25
Show Gist options
  • Save rohenaz/fb1865dcd23671aee95104128bb5b85d to your computer and use it in GitHub Desktop.
Save rohenaz/fb1865dcd23671aee95104128bb5b85d to your computer and use it in GitHub Desktop.
Pre-commit hook to automatically run standard
#!/bin/sh
# save as .git/hooks/pre-commit
# Run standard --fix before committing
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi
git diff --cached --name-only -z $against | xargs -0 standard --fix 1>&2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment