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


当前回答

在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: 

其他回答

只需尝试EDITOR=vim-gitcommit。

或者可以通过在bashrc中导出EDITOR=vim将EDITOR设置为vim。

Run:

git config --global core.editor "vim"

来自man git commit:

环境和配置变量用于编辑提交日志消息的编辑器将从GIT_editor环境变量、core.editor配置变量、VISUAL环境变量或editor环境变数中选择(按顺序)。

对于emacs用户

.emacs:

(server-start)

外壳:

export EDITOR=emacsclient

Windows:将记事本设置为默认的提交消息编辑器

git config --global core.editor notepad.exe

按Ctrl+S保存提交消息。要放弃,只需关闭记事本窗口而不保存。

如果您点击保存快捷方式,然后决定中止,请转到文件->另存为,在打开的对话框中,将“另存为类型”更改为“所有文件(*.*)”。您将看到一个名为“COMMIT_EDITMSG”的文件。删除它,然后关闭记事本窗口。

编辑:或者,更容易地从打开的记事本窗口中删除所有内容,然后单击保存。(感谢姆沃恩利的评论!)

我认为对于诸如提交消息之类的小记录,记事本是最好的,因为它很简单,有窗口,很快就能打开。当你有一大堆插件和东西时,甚至你的崇高也可能需要一两秒钟才能被激发起来。

在Git配置中设置core.editor:

git config --global core.editor "nano"

设置GIT_EDITOR环境变量:

export GIT_EDITOR=nano