如何全局配置git以使用特定的编辑器(例如vim)提交消息?


当前回答

在macOS Big Sur(11.0)测试版上,TextMate:所有环境变量选项都无效。(设置所有三个:GIT_EDITOR、VISUAL和EDITOR。)

最后,在git中设置全局core.editor,这起到了作用:git-config--全局core.editor“~/bin/mate-w”

其他回答

Atom作为您的git编辑器

git config --global core.editor "atom --wait"

需要将Atom配置为从命令行运行,以使上述功能正常工作:OS X:从Atom安装shell命令:菜单栏>Atom>安装Shell命令Windows:不需要任何操作-默认情况下,atom配置为从命令行运行

在windows 7中,当添加“Sublime”编辑器时,它仍然给我一个错误:

由于提交消息为空,正在中止提交。

Sublime无法保持焦点。

为了解决这个问题,我打开了c:\users/username/文件夹中的.gitconfig文件,并在单引号外添加了下面一行--wait选项。

[core]
      editor = 'F:/Program Files/Sublime Text 2/sublime_text.exe' --wait

希望对Sublime面临类似问题的人有所帮助。

在Ubuntu和Debian(谢谢@MichielB)上,也可以通过运行以下命令来更改默认编辑器:

sudo update-alternatives --config editor

这将提示以下内容:

There are 4 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /bin/nano            40        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
* 3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.tiny    10        manual mode

Press enter to keep the current choice[*], or type selection number: 

对于MAC,BBEdit:

首先,打开BBEdit,单击BBEdit徽标,然后选择Install Command Line Tools。

然后从命令行,

git config --global core.editor "BBEdit -w"

对于希望将neovim与Windows Subsystem For Linux一起使用的Windows用户:

git-config-core.editor“C:\Windows/system32/bash.exe--login-C'nvim.git/COMMIT_EDITMSG'”

这不是一个傻瓜式的解决方案,因为它不处理交互式的重新基础(例如)。非常欢迎改进!