Making git auto-commit

前端 未结 18 1805
面向向阳花
面向向阳花 2020-11-27 08:41

I\'d like to use git to record all the changes to a file.

Is there a way I can turn git \'commit\' on to automatically happen every time a file is updated - so ther

18条回答
  •  感动是毒
    2020-11-27 09:47

    This script doesn't run when a user changes the file, but it could be run as a cron job (by dropping it into an /etc/cron.* directory), which is also a reasonable solution.

    This script will iterate through your /srv/www directory (change it to wherever all of your sites are stored), add, commit, and push all files, and log everything to /var/log/gitlog.txt

    now=$(date +"%m.%d.%Y_%T")
    logfile='/var/log/gitlog.txt'
    
    for dir in /srv/www/*/
    do
    echo -e '\n' >> $logfile
    echo "autocommit $dir $now" >> $logfile
    echo "--------------------------" >> $logfile
    
    cd $dir
    git add . >> $logfile
    git commit -am "autocommit $now" >> $logfile
    git push origin master >> $logfile
    done
    

提交回复
热议问题