简体   繁体   English

用户推送到远程git repo时如何执行某些操作

[英]How to perform some action when a user pushes to a remote git repo

I have a service where users can 'deploy' data, but right now they have to manually execute the deployment once they make updates. 我有一项服务,用户可以在其中“部署”数据,但是现在他们一旦进行更新,就必须手动执行部署。 I would like to do it automatically when they push to a remote git repo that this service has access to. 当他们推送到该服务可以访问的远程git repo时,我想自动执行此操作。 Lets say the user has done the following in their local repo: 假设用户在其本地存储库中执行了以下操作:

git remote add AutoUpdater <whatever the URL is>

Then they make whatever updates to their local stuff, and push their commit to this remote repo: 然后,他们对本地内容进行任何更新,并将其提交推送到此远程存储库:

git add .
git commit -m "version x.x.x"
git push AutoUpdater master

How can I check this AutoUpdater repo to see when users have pushed changes and know when to take action? 如何检查此AutoUpdater库,以查看用户何时进行了更改并知道何时采取措施? I would prefer to use C#, which means I'll probably end up using LibGit2Sharp. 我更喜欢使用C#,这意味着我可能最终会使用LibGit2Sharp。

git provides a series of hooks which are run at different stages of the push process on the receiving side. git提供了一系列挂钩,这些挂钩在接收方的推送过程的不同阶段运行。 These can be executables of any kind and get information about what is being updated. 它们可以是任何类型的可执行文件,并可以获取有关正在更新的内容的信息。 This is the only way git provides for reacting to events. 这是git提供的对事件做出反应的唯一方法。

You can see a description of the hooks via git help hooks , and at http://git-scm.com/docs/githooks . 您可以通过git help hookshttp://git-scm.com/docs/githooks看到有关钩子的描述。 For reacting to updates, you'd likely want either the "post-update" or "post-receive" hooks, depending on how much data you'd like at once. 为了对更新做出反应,您可能希望使用“更新后”或“接收后”挂钩,具体取决于您一次要获取多少数据。

I would recommend this way above polling the reference list, which is what you'd have to resort to if you were to observe the repository from outside (via libgit2sharp or git or whatever else). 我建议在轮询参考列表上方使用此方法,如果要从外部观察存储库(通过libgit2sharp或git或其他方法),则必须采用此方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM