1

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!

3
  • What about 2 bash aliases? One to change your editor to X, and one to change it to nano? Then you can quickly change whenever you'd like with one command before you commit. Commented Jul 28, 2022 at 4:10
  • How about this? export GIT_EDITOR='nano' && git commit && unset GIT_EDITOR. Commented Jul 28, 2022 at 4:19
  • 2
    Simpler than the suggestion by qrsngky, but similar in spirit: Just do a GIT_EDITOR=nano git commit, and you then don't need to unset afterwards. Commented Jul 28, 2022 at 6:45

1 Answer 1

3

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.