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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:45:41+00:00 2026-05-31T09:45:41+00:00

My plan is to use git to keep track of changes in /etc but

  • 0

My plan is to use git to keep track of changes in /etc but when committing I want to have the person making the change specify themselves as author by adding the –author option on the commandline.

So I would like to stop accidental commits as root.

I tried creating this pre-commit hook but it is not working – git var is still returning root even if I specify the author on commit line.

AUTHOR=`git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/\1/p'`
if [ "$AUTHOR" == "root <root@localhost>" ];
then
   echo "Please commit under your own user name instead of \"$AUTHOR\":"
   echo 'git commit --author="Adrian"'
   echo "or if your name is not already in logs use full ident"
   echo 'git commit --author="Adrian Cornish <a@localhost>"'
   exit 1
fi
exit 0
  • 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-05-31T09:45:42+00:00Added an answer on May 31, 2026 at 9:45 am

    Until v1.7.10.1 (released 2012-05-01), Git did not make --author information available to Git hooks via environment variables, command-line arguments, or stdin. However, instead of requiring the use of the --author command line, you can instruct users to set the GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL environment variables:

    #!/bin/sh
    AUTHORINFO=$(git var GIT_AUTHOR_IDENT) || exit 1
    NAME=$(printf '%s\n' "${AUTHORINFO}" | sed -n 's/^\(.*\) <.*$/\1/p')
    EMAIL=$(printf '%s\n' "${AUTHORINFO}" | sed -n 's/^.* <\(.*\)> .*$/\1/p')
    [ "${NAME}" != root ] && [ "${EMAIL}" != "root@localhost" ] || {
        cat <<EOF >&2
    Please commit under your own name and email instead of "${NAME} <${EMAIL}>":
    GIT_AUTHOR_NAME="Your Name" GIT_AUTHOR_EMAIL="your@email.com" git commit
    EOF
        exit 1
    }
    

    Like the --author argument, these environment variables control the commit’s author. Because these environment variables are in Git’s environment, they’re also in the environment of the pre-commit hook. And because they’re in the environment of the pre-commit hook, they’re passed to git var GIT_AUTHOR_IDENT which uses them like git commit does.

    Unfortunately, setting these variables is much less convenient than using --author. If you can, upgrade to v1.7.10.1 or later.

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

Sidebar

Related Questions

I want to use Git to store and version data efficiently, but I also
Let me preface this by saying I am extremely new to git but have
I have a program for which I plan to use a lot of Timer
I'm working on a new project that I plan to keep in a git
I have to 3 servers, i plan to use one for nginx, others for
I plan to use some music on my site, but before I make it
The way I plan to use it is: At the seminar, have people send
If I do a query (I plan to use SDS.P) against the global catalog,
Need an async I/O Processing Plan to use async I/O through aio* calls on
I am developing a web app for which I plan to use InnoDB. However

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.