In most cases, if Emacs is used to edit a file in a git repository, it is advisable to commit within Emacs and use magit to write the commit message. However, if Emacs is not used to edit the files (such as only git mv
on the command line is used to move files around, or maybe just adding some image files), what should the config of git and Emacs be such that the correct magit mode is turned on when Emacs was fired up to edit the commit message, instead of the default plain text mode?
1 Answer
Make sure global-git-commit-mode
is enabled by putting
(global-git-commit-mode)
to your init file. (Actually, this mode will be enabled automatically once git-commit.el
is loaded, so you can also call (require 'git-commit)
instead. I prefer the more readable way). BTW, I am assuming you are using Emacs' built-in package manager package.el
.
Personally, I like doing all complex git operation within Magit, I define a shell function for this:
magit () {
emacsclient --eval "(call-interactively #'magit-status)"
open -a Emacs
}
(I use GUI Emacs on Mac and start Emacs server with (server-start)
)
then after type magit
from terminal, Emacs will jump out and Magit is ready to go.