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
Two solutions that I like are etckeeper -- which can be adapted to a custom directory other than /etc
:
mkdir /foo
etckeeper -d /foo init`
etckeeper -d /foo commit 'message'
And gitwatch -- specially the instructions of how to use it with supervisord.
I wrote a program, GitPrime, to provide autosave for your local Git repositories. Now easy to roll back to before you busted it! Bitbucket repository.
This should work on any platform that supports a bash shell including Windows+Cygwin.
If you know the name of the file and you want to monitor only one (or a few files), you can simply call "git commit" every few minutes to achieve this. If the file hasn't changed, git will just complain and you'll have to ignore this error but other than that, there will be no corruption.
In addition to that, you'll want to mark these files as "auto commit" in order to be able to commit manually as well. This way, the user can see the automatic changes and also the bigger "logical" changes which are accompanied by commit comments to explain that has changed since the last manual commit.
For example, use "AUTOCOMMIT" as the commit message. Later, you can write a tool to purge these commits using git log (to find out the revisions to kill) or you can try to create a branch AUTOCOMMIT using a brute force collision resolve strategy to hammer in the "manual commits".
Another option is to use the git low-level commands to build your own specialized repository.
Lastly, you could copy the file to a new name ("$filename.ac") while doing auto commits to distinguish between the manual and automatic versions.
I made this tiny shell script to monitor files status and trigger commands such as git commit on build success.
Feel free to download and try it.
https://github.com/nzvincent/nzvincent-github/blob/master/inotify-tools/inotify.sh
The previous answers recommending inotifywait for this job tipped me off in the right direction when I had this problem myself, so I wrote a little script. First this could only watch whole folders recursively (the opposite of Lester Buck's example), but then I also wanted to watch a file somewhere else, so I expanded it.
The result is a script currently called gitwatch
, as that is what it does: it watches a file or folder for changes (using inotifywait), and commits them to a git repository.
You can find the script, more info and instructions over on github: https://github.com/nevik/gitwatch
I'm pretty sure you'd need to hook that into whatever editor your users are using. You could write something to poll for changes, but depending on usage patterns, the polling frequency might need to be incredibly high to make sure it was picking up individual changes instead of multiple changes.