Making git auto-commit

前端 未结 18 1759
面向向阳花
面向向阳花 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:22

    The earlier inotifywait answer is great, but it isn't quite a complete solution. As written, it is a one shot commit for a one time change in a file. It does not work for the common case where editing a file creates a new inode with the original name. inotifywait -m apparently follows files by inode, not by name. Also, after the file has changed, it is not staged for git commit without git add or git commit -a. Making some adjustments, here is what I am using on Debian to track all changes to my calendar file:

    /etc/rc.local:

    
    su -c /home//bin/gitwait -l 
    
    

    /home//bin/gitwait:

    
    #!/bin/bash
    #
    # gitwait - watch file and git commit all changes as they happen
    #
    
    while true; do
    
      inotifywait -qq -e CLOSE_WRITE ~/.calendar/calendar
    
      cd ~/.calendar; git commit -a -m 'autocommit on change'
    
    done
    

    This could be generalized to wait on a list of files and/or directories, and the corresponding inotifywait processes, and restart each inotifywait as a file is changed.

提交回复
热议问题