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 8830025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:58:19+00:00 2026-06-14T07:58:19+00:00

I wrote a pre-commit hook to increment the version number in the source. Why

  • 0

I wrote a pre-commit hook to increment the version number in the source. Why are the changes applied after the commit? What can I do to do that prior to the commit?

#!/bin/sh
# Hook to increment version number before checkin

REPO_DIR=$(cd `dirname $0`/../.. && pwd)
VERS_FILE="${REPO_DIR}/version.php"
CUR_DATE=`date -u '+%Y-%m-%d %H:%M:%S'`
HOOK=`basename $0`

if [ -w ${VERS_FILE} ]; then
    # increment last digit of version string
    perl -i -pe 's/(\$version\s?=\s?['\''|"][\d\.]+)(\d+)/"$1".($2+1)/e' "${VERS_FILE}"
    RV=$?
    if [ 0 -ne ${RV} ]; then
        echo "ERROR: Updating version in ${VERS_FILE} failed"
        exit $RV
    fi
    echo "INFO: Increment version in file ${VERS_FILE}"
fi

echo "Finish $HOOK at $CUR_DATE"
exit 0

I’m aware that such automatic changes aren’t recommended. But technically this should be possible anyway. I’m using git 1.6.3.3 on Ubuntu 9.10.

  • 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-14T07:58:20+00:00Added an answer on June 14, 2026 at 7:58 am

    Your pre-commit script modifies the working tree copy of the file, but not the version in the index. The latter one is what actually gets committed.

    You need to git add the file after modifying it. But, doing this will mean that all changes to that file will be included in every commit even if you’re trying to commit just some changes from the working tree.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a pre-commit hook script that will alter a specific
I wrote the following pre-commit script for SVN to validate that a user has
i'm trying to write a SVN pre-commit hook script in Linux Bash that will
I'm trying to figure out how to write a pre-commit hook for Git that
I'm writing a pre-commit hook, or better, I'm editing the hook that comes standard
I'm writing a pre-commit hook in C# and I know I have to return
Using this hook with VisualSVN Server, added to the Repository/hooks folder as pre-commit.bat. My
I need to do the following: Write pre-commit hook in Perl Hook should check
I just wrote a simple extension that has permission to *.google.com and changes some
I'm trying to use a Git pre-commit hook to run some style checks and

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.