git commit can't find (global) config running in cron job

我与影子孤独终老i 提交于 2019-12-11 06:30:49

问题


I want to commit some file changes using a cron job calling a script with the following line in roots crontab

0 * * * * cd /files/ && ./backup.sh >/tmp/cronlog 2>/tmp/cronerror

the script looks as follows:

#!/usr/bin/env bash

… prepare the files for the backup …

echo "commit changes …"
git add -u
git commit -m "backup"
git push

Prior to the cron setup I've also set user.email and user.name for the root user and I've checked that the script runs if I call if from the command line.

But in /tmp/cronerror I receive the following well known message.

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
…

I've also tried setting HOME=/root in the script but this doesn't seam to make a difference.

Is there a way of telling the git command where to find the global git-config when running in a cron job?


回答1:


My solution is to use git config … without --global option which stores the configuration in the current repository, where git is able to find it.



来源:https://stackoverflow.com/questions/25139798/git-commit-cant-find-global-config-running-in-cron-job

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