如何全局配置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: 

其他回答

要使Visual Studio代码(vscode)成为默认的git编辑器,请执行以下操作:

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

对于emacs用户

.emacs:

(server-start)

外壳:

export EDITOR=emacsclient

对于希望使用Kinetics文本编辑器的Windows用户

创建一个名为“k.sh”的文件,添加以下文本并放置在主目录(~)中:

winpty "C:\Program Files (x86)\Kinesics Text Editor\x64\k.exe" $1

在git提示符下键入:

git config --global core.editor ~/k.sh

在Windows 7中,将编辑器设置为记事本++

打开任何文本编辑器。打开此文件:C:\Users\YOUR_USERNAME\.gitconfig将此部分添加到底部:


对于64位Notepad++,请使用:

[core]
    editor = 'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar

对于32位Notepad++,请使用:

[core]
    editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar

保存并关闭文件。使用git提交时,只需编写gitcommit并按Enter键。它将弹出记事本++。在文件顶部写入提交消息,然后保存并关闭文件。完成!

对于Windows,Neovim:

# .gitconfig

[core]
    editor='C:/tools/neovim/Neovim/bin/nvim-qt.exe'