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


当前回答

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

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

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

其他回答

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

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

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

在git提示符下键入:

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

对于IntelliJ用户

当我尝试git rebase时,我遇到了以下错误:'提示:正在等待编辑器关闭文件。。。code-n-w:code:未找到命令错误:编辑器“code-n-w”存在问题

当我试图将IntelliJ与Git关联时,出现了同样的错误:

问题是我没有在环境PATH变量中添加命令代码。我不想在我的终端上使用Visual Studio代码。这就是为什么它提示“命令未找到”。我通过删除

编辑器=代码-n-w

从.gitconfig文件的核心部分。Git再次正常工作。

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

在Git配置中设置core.editor:

git config --global core.editor "nano"

设置GIT_EDITOR环境变量:

export GIT_EDITOR=nano

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

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

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