On Linux you could use inotifywait to automatically execute a command every time a file’s content is changed.
Edit: the following command commits file.txt as soon as it is saved:
inotifywait -q -m -e CLOSE_WRITE --format="git commit -m 'autocommit on change' %w" file.txt | sh