Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to create a bash script for a git pre-commit hook. Whenever a commit is made, I want to check if files in a certain directory are part of the staged files and if so, run a command (Grunt task). So far I have everything working, except for only running if certain files are modified. I'm trying to get this to work:

if [ grep --quiet $SRC_PATTERN `git diff --cached --name-only` ]
  echo "none"
  exit 0

This is unfortunately giving me errors.

share|improve this question

1 Answer 1

up vote 2 down vote accepted


git diff --cached --name-only | if grep --quiet "$SRC_PATTERN"

Happy hacking

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.