In my crontab, I have the following line:
48 14 * * * bash /home/erelsgl/git/erel-sites/add-commit-push.bash "from home" 2&>1 >> /home/erelsgl/logs/backup_from_home.log
the script does what its name implies - add, commit and click:
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $DIR echo -------------------- date echo == add == /usr/bin/git add -A echo == commit == /usr/bin/git commit -m "$1" echo == pull == /usr/bin/git pull echo == push == /usr/bin/git push
As you can see from the log file, βcommitβ does nothing while βpullβ is working fine:
Fri Oct 23 14:48:01 IDT 2015 == add == == commit == == pull == Already up-to-date. == push ==
I executed the same command, a minute later, from the command line, and received the following log, which means that the commit occurred:
Fri Oct 23 14:49:31 IDT 2015 == add == == commit == On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working directory clean == pull == Already up-to-date. == push ==
What is the problem when committing from cron job?
NOTE. I also did the same experiment with the actual change in the test file. I found out that, indeed, the commit did not come from crontab (nothing was pressed upstream), but came from the command line.
git crontab
Erel segal-halevi
source share