Reputation: 4295
One of the reason for this question is that I cannot find username
(committer reported in example below) in any of the files:
grep -r obsdev .git/config ~/.gitconfig /etc/gitconfig
# no output
Apparently, there is another configuration source.
The point is that I don't want to learn about any possible configuration source existing now, or in the future, or order in which they apply and override each other. Instead, I want to let Git figure out and display final/effective author/committer values.
Under some conditions (like command line option --author
) Git displays commented out Author:
and Committer:
fields in editor for commit message:
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Author: First Last <[email protected]>
# Committer: username <[email protected]>
#
...
Is there a way to show these fields without trying to make a commit?
Alternatively, is it possible to force Git provide comments containing Author:
and Committer:
fields in the commit message editor under any circumstances without any command line options even when defaults are used (without overriding defaults)?
Upvotes: 3
Views: 1850
Reputation: 6646
You can use git var
:
# show the author (sed is there to strip the timestamp)
git var GIT_AUTHOR_IDENT | sed -r 's/( [^ ]+){2}$//'
# and the committer
git var GIT_COMMITTER_IDENT | sed -r 's/( [^ ]+){2}$//'
But if you haven't configured your name and email, it will print a warning instead of giving a value. A workaround would be:
# show the author
git var -l | grep -E '^GIT_AUTHOR_IDENT=' | sed -r 's/^[^=]+=//;s/( [^ ]+){2}$//'
# and the committer
git var -l | grep -E '^GIT_COMMITTER_IDENT=' | sed -r 's/^[^=]+=//;s/( [^ ]+){2}$//'
Upvotes: 4
Reputation: 265161
I'm not aware of any built in way to do that in Git. Git uses the config values user.name
and user.email
, which can be overridden by the environment variables $GIT_{COMMITTER,AUTHOR}_{NAME,EMAIL}
.
A simple shell script should get you the info you want:
NAME=$(git config user.name)
EMAIL=$(git config user.email)
echo "Author: ${GIT_AUTHOR_NAME:-$NAME} <${GIT_AUTHOR_EMAIL:-$EMAIL}>
echo "Committer: ${GIT_COMMITTER_NAME:-$NAME} <${GIT_COMMITTER_EMAIL:-$EMAIL}>"
See also git whoami
Upvotes: 1