Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show effective/actual author and committer used by Git

Tags:

git

Is there a Git command to display author and committer which would be used in the next commit based on all configuration sources applied?

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.

Example

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)?

like image 822
uvsmtid Avatar asked Nov 28 '25 23:11

uvsmtid


1 Answers

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}$//'
like image 155
Roman Avatar answered Dec 01 '25 13:12

Roman