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.
- Setup a
emacsclientto open in terminal. I have following shell script, in
#!/bin/sh /Applications/Emacs.app/Contents/MacOS/bin/emacsclient "$@" -t -a /Applications/Emacs.app/Contents/MacOS/Emacs -nw
If you are using Linux, the script can be simply changed into:
#!/bin/sh emacsclient "$@" -t -a emacs -nw
- 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)))
- 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)))
- Last thing is to specify
GIT_EDITORand you should be good to go.