Using Emacs for editing and properly formatting commit messages

As long as I remember, I have always been committing code to git from Command Line. Haven’t really used emacs and git integration. Unfortunately, that also meant – I was using vim from Command Line, for editing commit messages and doing interactive rebasing and stuff like that.

Today, I sat down and figured – how to do this properly from Emacs.

  1. Setup a emacsclient to open in terminal. I have following shell script, in $HOME/bin as fast_emacs:
    /Applications/ "$@" -t -a /Applications/ -nw

    If you are using Linux, the script can be simply changed into:

    emacsclient "$@" -t -a emacs -nw
  2. We also need to ensure that, when you are done with window (by pressing Control-X #), the buffers are cleaned up and stuff.
    (add-hook 'server-switch-hook
    	  (lambda ()
    	    (menu-bar-mode -1)))
    (add-hook 'server-done-hook (lambda nil (kill-buffer nil)))
  3. Next thing is to configure and load git-commit mode, which checks if your commit message is properly formatted or not:
    (require 'git-commit)
    (add-hook 'git-commit-mode-hook 'turn-on-flyspell)
    (add-hook 'git-commit-mode-hook (lambda () (toggle-save-place 0)))
  4. Last thing is to specify fast_emacs as GIT_EDITOR and you should be good to go.

2 thoughts on “Using Emacs for editing and properly formatting commit messages”

Leave a Reply

Your email address will not be published. Required fields are marked *