Re-format your files that are marked as “staged” with Prettier. Save this script as .git/hooks/pre-commit and give it execute permission.
Last active
June 28, 2025 14:15
-
-
Save peshala-prabhapoorna/0537c685c1b54ed36ed07f21d32e27a6 to your computer and use it in GitHub Desktop.
Prettier pre-commit hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Re-format your files that are marked as “staged” with Prettier | |
| FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') | |
| [ -z "$FILES" ] && exit 0 | |
| # Prettify all selected files | |
| echo "$FILES" | xargs ./node_modules/.bin/prettier --ignore-unknown --write | |
| # Add back the modified/prettified files to staging | |
| echo "$FILES" | xargs git add | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment