I'd like to be able to occasionally use a different editor when writing commit messages. I've found plenty of answers on how to change the default editor, but I don't want to change that - VIM is normally fine. What I'd like is some option like git commit --editor=<editor_name>
where <editor_name>
is the editor I want to use when writing the commit message for that commit only.
The only thing I've found that is similar to what I'd like is opening a new file with <editor_name> <newcommitfilename>
, write message, save and close file, then use git commit -F <newcommitfilename>
.
Is there an easier way to achieve this?
Thanks!
CodePudding user response:
All Git commands use the form:
git <verb>
You may insert options before the verb, e.g.,
git -c core.pager=cat show
The -c
option in particular takes a configuration item name, such as core.pager
, core.editor
, user.name
, and so on, and a value, joined with an equals sign =
like this.
Since your goal is to use a particular editor, git -c core.editor=whatever commit
does the trick.
As several commenters noted, there are other ways to do this. For the editor in particular, the environment variable $GIT_EDITOR
overrides core.editor
, so:
GIT_EDITOR=nano git commit
runs git commit
with GIT_EDTIOR
set to nano
for the duration of the one command (assuming POSIX-style shell).