当推送到服务器时获取所有提交
我正在做一个git post-commit挂钩将我的提交消息发布到Twitter。我在服务器上设置了钩子,这意味着它只在我拨打git push
时运行。当推送到服务器时获取所有提交
为了与python的git接口,我使用的是GitPython。在我的代码中,我使用repo.head.commit.message
来获取最新的提交消息。这意味着如果我推送多个提交,它只会得到最后一个提交。
这是我到目前为止。
class GITHelper:
"This class interacts with GIT for us"
def __init__(self, path):
repo = git.Repo(path)
headcommit = repo.head.commit
self.message = headcommit.message
self.author = headcommit.author.name
如何从推送中获取所有提交?或者,我如何获得推送的提交数量?
repo.iter_commits('master', max_count=5)
可以得到尽可能多的提交,所以如果我知道有多少提交,我可以使用它。
编辑:我测试,当我运行git push
,看来这个钩子获取从最后头承诺,不是我只是推。如何创建一个post-commit钩子来从我刚推送到服务器的提交中获取消息?
编辑2:我实际上使用更新挂钩,而不是后提交挂钩,是在服务器上使用正确的挂钩?
的githooks文档说:
The hook executes once for each ref to be updated, and takes three parameters:
- the name of the ref being updated,
- the old object name stored in the ref,
- and the new objectname to be stored in the ref.
所以,检查你的脚本得到的参数,你也应该得到新的裁判,然后你就可以在新老裁判之间找出提交。如果它是一个shell脚本,你可以这样做:
git log --oneline $oldRef..$newRef
谢谢。我对git还是有点新鲜的,所以我不是100%钩子是如何工作的。现在看看GitPython是否有办法获得2个裁判之间的提交。 – 2011-06-09 14:21:02
http://twitter.com/isnotrss – 2011-06-09 03:26:42