Difference between pre-push and pre-receive hook in git?

淺唱寂寞╮ 提交于 2019-12-04 12:57:36

问题


Is there a difference between pre-push and pre-receive hook in git, in terms of use case or working logic?
The only difference I could understand from their documentation was in terms of the input they receive -

1.Pre-Push : Information about what is to be pushed is provided on the hook's standard input with lines of the form - local ref SP local sha1 SP remote ref SP remote sha1 LF

2.Pre-receive : For each ref to be updated it receives on standard input a line of the format -
old-value SP new-value SP ref-name LF
However, I would like to know if there are particular use cases for each hook or can they be used interchangeably?


回答1:


One (pre-push) is a client-side hook, the other (pre-receive) is a server-side hook.

In that aspect, they are very different, and if you want to enforce consistently a given policy, you often do it in a pre-receive (server side) hook. That way, you don't have to worry about deploying a pre-push hook on each client.

Remember: hooks are local to a repo, which means a pre-push hook cannot easily be distributed to any downstream repo. But if those downstream repos are all referring to the same upstream repo, a pre-receive hook can apply to them all.



来源:https://stackoverflow.com/questions/25440207/difference-between-pre-push-and-pre-receive-hook-in-git

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!