Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8014115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:49:55+00:00 2026-06-04T19:49:55+00:00

I am trying (but failing miserably) to make a git pre-commit hook that checks

  • 0

I am trying (but failing miserably) to make a git pre-commit hook that checks for the presence of a var_dump in my modified files and exits if it finds one. The problem that I’m having is that it appears to always be aborting the commit. Here is the contents of my pre-commit file:

VAR=$(git diff | grep -w "var_dump")
if [ -z $VAR ]; then
  echo "You've left a var_dump in one of your files! Aborting commit..."
  exit 1
fi
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:49:57+00:00Added an answer on June 4, 2026 at 7:49 pm

    First of all, note that plain git diff gives the difference between the working tree and the index (i.e. what can still be staged), not what is about to be committed. Use git diff --cached to see what is about to be committed.

    The second thing I encountered as I was experimenting was that using if [ -z $VAR ] directly threw an error, because the + at the beginning of the git diff output was interpreted by Bash. Make sure to surround $VAR with quotes to prevent this.

    As for the script, you forgot to negate the test if $VAR is empty. If the output from grep is empty, then “var_dump” was not found, and the hook should return success. The case you want is if it is not empty, meaning “var_dump” was found, and it should abort the commit.

    All together:

    VAR=$(git diff --cached | grep -w "var_dump")
    if [ ! -z "$VAR" ]; then
      echo "You've left a var_dump in one of your files! Aborting commit..."
      exit 1
    fi 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to create an uebersimple class that implements get enumerator, but failing madly due
I'm trying to make sense of, but failing to, the documentation's distinction between singleTask
Hello—I am trying (and failing miserably) to make these Social Media icons in the
I am trying to play with jQuery mouseenter and mouseleave events but failing. Here
I´ve just started learning GWT and I´m trying to implement http://gwt.google.com/samples/Showcase/Showcase.html#!CwFileUpload and but failing
I'm trying to retrieve hierarchical data from a table but am failing to do
I am trying to do this but keep on failing. I have a text
i am really trying to do this but i am failing to find a
I am trying to call ejabberdctl from a PHP file, but it is failing
So I am trying to set up a basic timer but I am failing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.