Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make git post-receive emails be sent from the commit author?

I'm using the post-receive-email script included with git. (Source is here.) It works just fine, but I want each email to be sent from the author of the commits pushed. How do I do it?

My post-receive file currently looks like this, and I want to customize the from-email-address.

#!/bin/sh

export [email protected]
$(dirname $0)/post-receive-email
like image 788
Jonathan Tran Avatar asked Mar 06 '26 23:03

Jonathan Tran


1 Answers

Use git log to pull out the email address.

For example, in post-receive:

#!/bin/sh

# Use the email address of the author of the last commit.
export USER_EMAIL=$(git log -1 --format=format:%ae HEAD)
$(dirname $0)/post-receive-email

You could also map the email addresses, if for example, people are using their gmail or personal domain addresses, but you would like to map them to a single domain.

#!/bin/sh

# Use the mapped email address (specified in .mailmap) of the author of the last commit.
export USER_EMAIL=$(git log -1 --format=format:%aE HEAD)
$(dirname $0)/post-receive-email

You can read more about .mailmap here.

like image 136
Jonathan Tran Avatar answered Mar 09 '26 11:03

Jonathan Tran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!