Git:从存储库自动拉取?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9978400/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:21:33  来源:igfitidea点击:

Git: auto pull from repository?

gitdeployment

提问by Li Haoyi

Is there any way to set up git such that it listens for updates from a remote repo and will pull whenever something changes? The use case is I want to deploy a web app using git (so I get version control of the deployed application) but want to put the "central" git repo on Github rather than on the web server (Github's interface is just soooo nice).

有什么方法可以设置 git 以便它侦听来自远程仓库的更新并在发生变化时拉取?用例是我想使用 git 部署一个 web 应用程序(所以我得到了部署应用程序的版本控制)但想将“中央”git repo 放在 Github 而不是 Web 服务器上(Github 的界面非常好) .

Has anyone gotten this working? How does Heroku do it? My Google-fu is failing to give me any relevant results.

有没有人得到这个工作?Heroku 是如何做到的?我的 Google-fu 没有给我任何相关结果。

采纳答案by ksol

Git has "hooks", actions that can be executed after other actions. What you seem to be looking for is "post-receive hook". In the github admin, you can set up a post-receive url that will be hit (with a payload containing data about what was just pushed) everytime somebody pushes to your repo.

Git 有“钩子”,可以在其他动作之后执行的动作。您似乎正在寻找的是“接收后挂钩”。在 github 管理员中,您可以设置一个 post-receive url,每当有人推送到您的 repo 时,该 url 都会被命中(带有包含有关刚刚推送的内容的数据的有效负载)。

For what it's worth, I don't think auto-pull is a good idea -- what if something wrong was pushed to your branch ? I'd use a tool like capistrano(or an equivalent) for such things.

就其价值而言,我认为自动拉取不是一个好主意 - 如果将错误推送到您的分支怎么办?capistrano对于此类事情,我会使用类似(或等效工具)的工具。

回答by SigTerm

On unix-likes you can create cron job that calls "git pull" (every day or every week or whatever) on your machine. On windows you could use task scheduler or "AT" command to do the same thing.

在类 Unix 上,您可以在您的机器上创建调用“git pull”(每天或每周或其他)的 cron 作业。在 Windows 上,您可以使用任务调度程序或“AT”命令来做同样的事情。

回答by Pavel Niedoba

There are continuous integrations programs like Jenkins or Bamboo, which can detect commits and trigger operations like build, test, package and deploy. They do what you want, but they are heavy with dependencies, hard to configure and in the end they may use periodical check against git repository, which would have same effect like calling git pull by cron every minute.

有像 Jenkins 或 Bamboo 这样的持续集成程序,它们可以检测提交并触发构建、测试、打包和部署等操作。他们做你想做的事,但他们有很多依赖,难以配置,最后他们可能会定期检查 git 存储库,这与每分钟通过 cron 调用 git pull 具有相同的效果。

回答by Ioannis Kokkinis

I know this question is a bit old, but you can use the windows log and git to autopull your project using a webhook and php (assuming your project involves a webserver. See my gist here : https://gist.github.com/upggr/a6d92e2808e9628ebe0d01fd93569f4a

我知道这个问题有点老了,但是您可以使用 Windows 日志和 git 使用 webhook 和 php 自动拉取您的项目(假设您的项目涉及网络服务器。请在此处查看我的要点:https: //gist.github.com/ upggr/a6d92e2808e9628ebe0d01fd93569f4a