Search code examples
giteditorgit-commit

Is there a way to specify an editor on a git command in a one-off style


Is run git using a one-off override to the git editor:

$ git commit -m "my first commit" --editor="vim"

That will allow me to change the default editor without having to touch the GIT configuration.

Examples where this might be useful:

  • When squashing lengthy histories or writing up messages for a feature commit.
  • When performing automated edits to a commit, allowing a custom-script to manipulate the contents instead of a text editor.

Solution

  • You can override GIT_EDITOR environment variable just for one git execution:

    GIT_EDITOR=nano git commit -a