Git:接收后电子邮件挂钩,包括差异补丁?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/804601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: post-receive email hook, including diff patches?
提问by
I found a post-receive hook for Git after some googling that I use to e-mail all commits to a remote/shared repo.
在谷歌搜索之后,我发现了一个 Git 的 post-receive 钩子,我用它来将所有提交通过电子邮件发送到远程/共享存储库。
The problem with this post-receive hookis that it only has the capability to provide who made the commit, the log message, date, file(s) affected. I also want to see the affected file(s) generated patches in the e-mail to see what changes were made to the code. Subversion does this rather nicely.
这个post-receive hook的问题在于它只能提供谁进行了提交、日志消息、日期、受影响的文件。我还想在电子邮件中查看受影响的文件生成的补丁,以了解对代码进行了哪些更改。Subversion 很好地做到了这一点。
Does anyone have a solution for perhaps an env-variable that may be passed to the post-receive hook that does this? Or even better, an example that is already cooked up?
有没有人有可能传递给执行此操作的接收后挂钩的环境变量的解决方案?或者更好的是,一个已经准备好的例子?
Thanks all!
谢谢大家!
采纳答案by Bombe
Recent Git version should install a post-receive-email
script. In it, it says:
最近的 Git 版本应该安装一个post-receive-email
脚本。在里面,它说:
hooks.showrev
The shell command used to format each revision in the email, with "%s" replaced with the commit id. Defaults to "git rev-list -1 --pretty %s", displaying the commit id, author, date and log message. To list full patches separated by a blank line, you could set this to "git show -C %s; echo".
钩子.showrev
用于格式化电子邮件中每个修订的 shell 命令,将“%s”替换为提交 ID。默认为“git rev-list -1 --pretty %s”,显示提交 ID、作者、日期和日志消息。要列出由空行分隔的完整补丁,您可以将其设置为“git show -C %s; echo”。
So just set hooks.showrev
to “git show -C %s; echo” in the repository with the email hook and you're all set.
所以只需设置hooks.showrev
为“git show -C %s; echo”在存储库中使用电子邮件钩子,你就全部设置好了。
回答by HiQ CJ
I had similar issues here:
我在这里遇到了类似的问题:
Git hook to send email notification on repo changes
Actually there are different versions of the post-receive-email script - the one available on git.kernel.org informs about and respects hooks.showrev, the one I had did not.
实际上有不同版本的 post-receive-email 脚本 - git.kernel.org 上可用的版本通知并尊重 hooks.showrev,而我没有的版本。
But this discussion is cool, thanks, will definitely look at it! The other script linked above also has gitweb link feature and stuff, how are you others doing on that?
但是这个讨论很酷,谢谢,一定会看的!上面链接的另一个脚本也有 gitweb 链接功能和东西,你其他人在这方面做得如何?
回答by Yang
Even though this question already has an accepted answer, I thought this was one of the nicer post-receive mailer hooks that I've come across:
尽管这个问题已经有一个公认的答案,但我认为这是我遇到的更好的接收后邮件钩子之一:
http://github.com/brasse/post_receive_email.py
http://github.com/brasse/post_receive_email.py
Discovered via the author's blog post:
通过作者的博客文章发现:
http://copypasteprogrammer.blogspot.com/2010/03/git-post-receive-hook-in-python.html
http://copypasteprogrammer.blogspot.com/2010/03/git-post-receive-hook-in-python.html
回答by nacho
Here you have another in case you are interested with colors etc: https://github.com/nacho/email-hook
如果您对颜色等感兴趣,这里还有另一个:https: //github.com/nacho/email-hook
回答by Dustin
I haven't run it in a while, but (I believe) the one I used to useis online. I took what used to ship with git and rearranged it more for my liking. I haven't tried running anything similar in a long time.
我已经有一段时间没有运行它了,但是(我相信)我曾经使用的那个是在线的。我采用了过去随 git 一起提供的内容,并根据自己的喜好重新安排了更多内容。我很久没有尝试运行类似的东西了。
I've got a few screenshots of what it did:
我有一些它所做的事情的截图:
- Normal push(two commits)
- Tag creation(replacing previous tag)
- Pushed rebase
回答by robinr
See this section.
请参阅本节。
echo ""
echo "Summary of changes:"
git diff-tree --stat --summary --find-copies-harder $oldrev..$newrev
Here git is asked for the diff, but then it is also asked to summarize it. Remove the --stat and --summary flags and you will see the diff.
这里 git 被要求提供差异,但随后也被要求对其进行总结。删除 --stat 和 --summary 标志,您将看到差异。
git diff-tree --find-copies-harder $oldrev..$newrev
Here is another way that shows all revisions including diffs from $oldrev to $newrev
这是显示所有修订的另一种方式,包括从 $oldrev 到 $newrev 的差异
git --no-pager log --find-copies-harder $oldrev..$newrev