git - 如何让提交作者发送 git post-receive 电子邮件?

标签 git email hook post-commit

我正在使用 git 中包含的 post-receive-email 脚本。 (来源是 here 。)它工作得很好,但我希望每封电子邮件都是从推送的提交的作者那里发送的。我该怎么做?

我的 post-receive 文件目前看起来像这样,我想自定义发件人电子邮件地址。

#!/bin/sh

export USER_EMAIL=from-email-address@blah.com
$(dirname $0)/post-receive-email

最佳答案

使用 git log 提取电子邮件地址。

例如,在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

您还可以映射电子邮件地址,例如,如果人们使用他们的 gmail 或个人域地址,但您希望将它们映射到单个域。

#!/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

您可以阅读有关 .mailmap 的更多信息 here .

关于git - 如何让提交作者发送 git post-receive 电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2443908/

相关文章:

git - 管理git存储库的最佳方式

git - 如何在所有分支之间同步错误修复?

python - 如何从登录管理员的用户发送电子邮件?

python - SMTPSenderRefused - 553,发件人地址未验证 - Django 电子邮件表单

iphone - 当用户尝试在 iOS 中打开电子邮件附件时如何显示 "Open In..."

c# - 如何连接 Youtube 视频(Flash Player?)以减慢播放速度?

python - 如何编写一个git hook来限制写入分支?

git - Visual Studio 2015 git不显示所有历史记录,仅显示第一次提交

windows - 如何将 Araxis 设置为 MSYS git 的差异/merge 工具?

windows-services - Windows 服务还是托盘/NotifyIcon?