Saturday 13 October 2018

How do I create a cron job that will commit my project changes to git on a weekly basis


I'm using git for the purposes of making a historical transcript of the changes made to my project. I understand it's not the ideal usage but it's the usage pattern I've chosen for various reasons which I won't get into for the sake of brevity.


How would I create a cron job that would commit the changes to the repository each day or week?


I'm using the latest version of git on Ubuntu 10.10.



Answer



0 20 * * 0 /path_to_script

That will run the command specified (replace /path_to_script') at 20:00 local time every Sunday. The syntax for cron jobs is fairly simple, and there's a slick tool that will help you create them without remembering the code positions.


In this case, the command should be a script that runs the commit for you. I think it would be easiest in your case to write a quick shell script to change to the clone directory and then run the commit. Create a file at ~/commit.sh and put this in it (replacing /location/of/clone, of course)



#!/bin/sh
cd /location/of/clone
git-commit -m "commit message, to avoid being prompted interactively"

Then chmod +x ~/commit.sh to make it executable, and have the cron job run that (referring to it by it's full path, rather than using ~).


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...