Thursday, April 26, 2012

git autocommit ftw

After an unfortunate incident involving "R --slave > analysis.r" rather than "R --slave < analysis.r", I've added the following to my .emacs:

(require 'log-edit)
(add-hook 'after-save-hook '(lambda ()
  (if (vc-git-registered (buffer-file-name))
    (vc-git-checkin (buffer-file-name) nil (format-time-string "Autocommit %F %T")))))

Such that if I'm in a git repo, every save gets committed. So, I'll need to find a new stupid mistake to destroy my work.
 
I also learned that a list of unpushed commits can be viewed with "git log origin/master..HEAD".

Update: See Autocommit II for an improved version.

No comments: