0

When I run git commit, my favourite editor starts and presents me with something like this:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Your branch is up-to-date with 'origin/master'.
#
# Changes to be committed:
# …

I work on many different projects in different context, and as such have various Git identities. More than once I have to change an existing commit (or worse, a chain of existing commits) because I forgot to run git config user.email.

Is it possible to show the current identity in the comments of the commit message, so that I see it when I write my commit message? That would help me to discover mistakes earlier.

Something along the lines of this would be fine:

# Author:
# jornane <[email protected]>

1 Answer 1

0

You didn't specify what OS you are using but on Linux you can achieve what you want using the following prepare-commit-msg:

#!/usr/bin/env sh

# prepare-commit-msg: print author name and e-mail as a comment in a commit message
#                     automatically

# if amend, don't do anything
if ! [ -z $3 ] ;then
    exit
fi


author=$(git var GIT_AUTHOR_IDENT | grep -E -o ".*<.+>")

sed -i "1s/^/#$author \n/" $1
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .