====== STR Start ======
git init test
cd test
touch test.txt
cd .git/hooks
mv prepare-commit-msg.sample prepare-commit-msg
nano prepare-commit-msg
Paste the following:
#!/bin/sh
echo "GIT_AUTHOR_NAME:" $GIT_AUTHOR_NAME
echo "GIT_AUTHOR_EMAIL:" $GIT_AUTHOR_EMAIL
AUTHOR_INFO=$(git var GIT_AUTHOR_IDENT)
echo "AUTHOR_INFO:" $AUTHOR_INFO
cd ../..
git add .
git commit -m "Test"
====== STR End ======
Output on one machine (Debian12) is:
GIT_AUTHOR_NAME: <My Name>
GIT_AUTHOR_EMAIL: <Account>@<Hostname>
AUTHOR_INFO: <My Name> <<Account>@<Hostname>> <Timestamp>
Output on my Windows is:
GIT_AUTHOR_NAME: <My Name>
GIT_AUTHOR_EMAIL: <Account>@<Company>.com
AUTHOR_INFO: <My Name> <<Account>@<Company>.com> <Timestamp>
Where does git get this information from? I verified that the following are empty
git config --system user.name
git config --local user.name
git config --global user.name
git conifg --worktree user.name
(same with email) and I do not have GIT_AUTHOR_NAME
or GIT_AUTHOR_EMAIL
set.
What I want to do:
I would like to write a git hook that verifies that the --author
option was used with git commit
. The fact that these variables are read from the system (hostname, accountname, etc) makes this difficult.
How can I achieve that?