每小时 GIT 推送

ir-*_*r-g 9 command-line scripts cron git

我是否可以通过批处理脚本每小时自动执行一次Git推送。

我通常会输入:

git add *
git commit -m "latest update"
git push https://username:password@github.com/username/repository.git master
Run Code Online (Sandbox Code Playgroud)

我怎样才能自动化这个?

小智 8

是的,你可以用 cron 做到这一点。要将任务添加到 cron,您需要运行

crontab -e
Run Code Online (Sandbox Code Playgroud)

语法应该在最后一行的注释中指定,但我还是会解释一下:

mh dom mon dow 命令 按顺序:这些是分钟、小时、月份日期、月份、星期几以及此时要运行的命令。

因此,要每小时运行一次,您需要:

0 * * * * /home/username/bin/git-backup-script.sh
Run Code Online (Sandbox Code Playgroud)

这意味着在每天每小时的第 0 分钟运行脚本等。

其中 /home/username/bin/git-backup-script.sh 是一个 shell 脚本,可以完成你提到的所有事情(尽管不要忘记 cd 到其中的相关目录!)