git pull 自动通过 crontab
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13607734/
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
git pull automatic via crontab
提问by lastria
I would like to sync my git repository on my server to my local webserver. All the guides I read caused different errors and now I'm really desperate. I'm sorry if you already read this question a hundred times, but I still don't get it -.-
我想将我服务器上的 git 存储库同步到我的本地网络服务器。我阅读的所有指南都导致了不同的错误,现在我真的很绝望。对不起,如果你已经阅读了这个问题一百遍,但我仍然不明白-.-
- Working with Linux SuSE and conneting on it with PuTTY via SSH
- the webprojekt where I need the sync is on the folder: /srv/www/htdocs/my_project
- the git repository is here: /srv/git/repository/my_project
- I have the users: "root" and "cron"
- 使用 Linux SuSE 并通过 SSH 与 PuTTY 连接
- 我需要同步的 webprojekt 位于文件夹中:/srv/www/htdocs/my_project
- git 存储库在这里:/srv/git/repository/my_project
- 我有用户:“root”和“cron”
The cron should do this commands every minute or less with the user "cron":
cron 应该每分钟或更短时间使用用户“cron”执行此命令:
cd /srv/www/htdocs/my_project
git pull origin
(git fetch) <-- not mandatory
These commands work fine when I input them manually. (except I have to enter the user password every time)
当我手动输入它们时,这些命令工作正常。(除了我每次都必须输入用户密码)
In this question I got some informations, but I always get an error when I try them myself.
My cron should look like this then:
我的 cron 应该如下所示:
* * * * * su -s /bin/sh cron -c 'cd /srv/www/htdocs/my_project && /usr/local/bin/git pull origin master'
I executed this on my PuTTY, which answered me: -bash: bin: command not found
我在我的 PuTTY 上执行了这个,它回答了我:-bash: bin: command not found
My next try was:
我的下一次尝试是:
crontab * * * * * su -s /bin/sh cron -c 'cd /srv/www/htdocs/my_project && /usr/local/bin/git pull origin master'
Error: crontab: invalid option -- 's'
错误:crontab:无效选项 -- 's'
Error: crontab: usage error: unrecognized option
错误:crontab:使用错误:无法识别的选项
I tried a lot more combinations (removing the su -s or removing the -c etc.) but it never worked as I wanted -.- Shouldn't I do this command on PuTTY?
我尝试了更多的组合(删除 su -s 或删除 -c 等)但它从来没有像我想要的那样工作 -.- 我不应该在 PuTTY 上执行这个命令吗?
Good to know: I'm a linux and GIT beginner, started working with it yesterday and actually managed to do a lot til now. (^.^) So I would be happy to have an understandable explanation, in what I do wrong and what I have to do. It's confusing.
很高兴知道:我是 linux 和 GIT 初学者,昨天开始使用它,直到现在实际上已经做了很多。( ^.^) 所以我很高兴有一个可以理解的解释,我做错了什么,我必须做什么。这很混乱。
采纳答案by Chronial
The easiest way to achieve what you want (have the git repository automatically deployed on your server) is by putting the git repository inside you webserver and using a hook to do a check out on push. How to this is described in this answer: Deploy a project using Git push
实现您想要的(将 git 存储库自动部署在您的服务器上)的最简单方法是将 git 存储库放在您的网络服务器中并使用钩子检查推送。此答案中描述了如何执行此操作:使用 Git 推送部署项目