Setting Up Git Commit Email Notifications
2012-10-11 16:31
274 查看
A method to send email notification to a list email addresses by the remote git server after every push from the client will be introduced.
After the client pushing to the git server, several actions are triggered. These actions are done by hooks. Hooks are scripts placed in the GIT_DIR/hooks directory. Here, GIT_DIR is the directory of the git repository on the git server. One of the trigger action
is post-receive, so we can put a executable script with name post-receive under GIT_DIR/hooks.
For every push by client, post-receive will be executed to send email notification.
A
sample notification email after client pushing two commits is show in the graph on the right. The subject contains a prefix, the repository name and the last commit message. The body of the email contains the commit log and summary of the changes.
Now lets go to the detail of configuring the mechanism.
My script that sends email like the example described above can be downloaded from: git
post-receive script.
Or view the source code: git
post-receive script
This script use smtp server to send email. You need to change the smtp server address at the end of the script. Simply change smtp=”smtp://smtp.cse.ust.hk” to the smtp server you use. You can not use my smtp server which is only allowed to send email without
authorization inside of CSD in HKUST. If you like to use Gmail’s smtp, please refer to Sending
Email from mailx Command on Linux Using Gmail’s Smtp.
This script is changed from Andy Parkins’s one which is in git’s distribution. On fedora 12, the original script can be found under /usr/share/git-core/contrib/hooks.
After getting the post-receive script, you need to copy it to GIT_DIR/hooks/ directory on the
git server.
Please note that this script should be executable. You may need to add executable mod bits to post-receive by
when you are in GIT_DIR.
The repository name in the email subject is the first line of $GIT_DIR/description. Change the first line of the description file to you project’s name.
The sender’s email address, the mail list and the subject prefix is defined in GIT_DIR/config file. I like to edit this config file by hand which is as easy as using git config command.
Add these line to the config file:
The email addressed in mailing list is separated by space.
The default subject prefix is [GIT]. You can change it to any string you like by add hooks.emailprefix in config.
Now the email notification mechanism has been set up. You can change the script if more functions is needed.
原文链接:http://www.fclose.com/b/linux/1473/setting-up-git-commit-email-notification/
After the client pushing to the git server, several actions are triggered. These actions are done by hooks. Hooks are scripts placed in the GIT_DIR/hooks directory. Here, GIT_DIR is the directory of the git repository on the git server. One of the trigger action
is post-receive, so we can put a executable script with name post-receive under GIT_DIR/hooks.
For every push by client, post-receive will be executed to send email notification.
A
sample notification email after client pushing two commits is show in the graph on the right. The subject contains a prefix, the repository name and the last commit message. The body of the email contains the commit log and summary of the changes.
Now lets go to the detail of configuring the mechanism.
Get the post-receive script
My script that sends email like the example described above can be downloaded from: gitpost-receive script.
Or view the source code: git
post-receive script
This script use smtp server to send email. You need to change the smtp server address at the end of the script. Simply change smtp=”smtp://smtp.cse.ust.hk” to the smtp server you use. You can not use my smtp server which is only allowed to send email without
authorization inside of CSD in HKUST. If you like to use Gmail’s smtp, please refer to Sending
Email from mailx Command on Linux Using Gmail’s Smtp.
This script is changed from Andy Parkins’s one which is in git’s distribution. On fedora 12, the original script can be found under /usr/share/git-core/contrib/hooks.
Put post-receive into hooks directory
After getting the post-receive script, you need to copy it to GIT_DIR/hooks/ directory on thegit server.
Please note that this script should be executable. You may need to add executable mod bits to post-receive by
chmod a+x hooks/post-receive
when you are in GIT_DIR.
Change repository description
The repository name in the email subject is the first line of $GIT_DIR/description. Change the first line of the description file to you project’s name.
Change config
The sender’s email address, the mail list and the subject prefix is defined in GIT_DIR/config file. I like to edit this config file by hand which is as easy as using git config command.Add these line to the config file:
[hooks] mailinglist = "email1@example.com email2@example.com" senderemail = "owner@exmaple.com"
The email addressed in mailing list is separated by space.
The default subject prefix is [GIT]. You can change it to any string you like by add hooks.emailprefix in config.
Now the email notification mechanism has been set up. You can change the script if more functions is needed.
原文链接:http://www.fclose.com/b/linux/1473/setting-up-git-commit-email-notification/
相关文章推荐
- git commit Please tell me who you are it config --global user.email "you@example.com"
- Setting up a git remote origin
- Setting Up Git Server Using Gitosis
- git修改user.name和user.email后找回之前的commit
- Setting Up Google Code And Github With Git
- Setting up a Git project
- Setting up email message filters in Outlook
- Xcode git commit失败 unable to auto-detect email address
- Setting up Git on CentOS 5 server
- Setting up a git server on MacOS X Lion
- Setting your email in Git
- Git在提交的时候:user name and email must be set brfore commit.
- [Practical Git] Clean up commits with git rebase
- Setting up a new remote git repository
- setting up a new remote git repository
- git commit的--amend选项
- git pull冲突:commit your changes or stash them before you can merge.
- 使用vqsignup实现web方式的email账号申请(qmail系列文章)
- git cherry-pick. 如何把已经提交的commit, 从一个分支放到另一个分支
- Setting up Unicorn with Nginx