在服务器端使用 git hooks,是否可以在每次有人推送到远程存储库时循环从客户端发送到服务器的新提交消息?
我需要从每条消息中提取信息,
哈希、日期、提交作者、分支
我找不到任何关于 git hooks 的好的文档来解决这个问题。
我已读完git post-receive 钩子,抓取提交消息并回发到 URL https://stackoverflow.com/questions/8263186/git-post-receive-hook-that-grabs-commit-messages-and-posts-back-to-url
我不明白一行简单的代码
正如中所解释的githooks 手册页 https://www.kernel.org/pub/software/scm/git/docs/githooks.html,post-receive hook 为每个 ref 获取一行,包含
SP SP OF
其中 是存储在 ref 中的旧对象名称, 是要存储在 ref 中的新对象名称, 是 ref 的全名。
所以,如果你把这个放进去.git/hooks/post-receive
:
#!/bin/sh
while read oldvalue newvalue refname
do
git log -1 --format='%H,%cd,%an' $newvalue
git branch --contains $newvalue | cut -d' ' -f2
done
The while
语句使其循环遍历每一行,将行中的三个字段读入变量$oldvalue
, $newvalue
and $refname
The git log
行将输出哈希,日期,将作者提交到标准输出。
The git branch
线将尝试输出分支 https://stackoverflow.com/questions/2706797/git-finding-what-branch-a-commit-came-from。 (或者你可以使用echo $refname
,将以格式输出refs/heads/master
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)