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

其他回答

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

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

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

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

在git提示符下键入:

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

这为找到这个问题的人提供了一个答案,他们可能希望链接vim以外的编辑器。

Github提供的链接资源很可能会在编辑更新时保持最新,即使SO(包括这个)上的答案不是这样。

将文本编辑器与git关联

Github的帖子准确地显示了各种编辑器在命令行中输入的内容,包括特定于每个编辑器的选项/标志,以使其与git配合得更好。

记事本++:git-config--global-core.editor“'C:/Program Files(x86)/Notepad++/nopad++.exe'-multeInst-notibbar-nosession-noPlugin”

Sublime文本:git-config--全局core.editor“'c:/Program Files\sublimitext 3/subl.exe'-w”

原子:git-config--全局core.editor“atom--等待”

上面的命令假设您的编辑器已安装在windows计算机的默认目录中。

这些命令基本上将双引号之间的文本添加到主目录中的.gitconfig。在windows计算机上,主页可能是C:\Users\您的用户名,其中您的用户名是您的登录名。在命令行中,您可以通过键入cd~来访问此目录。

例如,上面的命令将在[core]部分下面添加以下行,如下所示:[核心]editor='C:/Program Files\sublime text 3/subl.exe'-w

如果您有不同的编辑器,只需使用上述任一方法替换为编辑器的路径。(希望不需要任何标志来实现最佳使用。)

有一个命令列表,您可以使用,但对于vs代码,请使用此命令

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

这是所有编辑器的链接:https://git-scm.com/book/en/v2/Appendix-C%3A-Git命令设置和配置