如何全局配置git在提交信息时使用特定的编辑器(例如vim
)?
如何全局配置git在提交信息时使用特定的编辑器(例如vim
)?
针对想在Windows子系统中使用neovim的用户:
git config core.editor "C:/Windows/system32/bash.exe --login -c 'nvim .git/COMMIT_EDITMSG'"
这并不是一个万无一失的解决方案,因为它不能处理交互式变基(例如)。欢迎提出改进意见!
我来这里是寻找一次性解决方案的(在我的情况下,我通常使用vim
,但这一次我想使用VS Code)只针对单个命令,其他人可能也想知道:
GIT_EDITOR='code -w' git rebase -i …
以下是与上下文相关的git
/hub
版本:
git version 2.24.2 (Apple Git-127)
hub version 2.14.1
git config --global core.editor "open -n -W -a TextWrangler"
git config --global core.editor "~/bin/mate -w"
# .gitconfig
[core]
editor='C:/tools/neovim/Neovim/bin/nvim-qt.exe'
git config --global sequence.editor "gvim" # or whatever your prefer
gvim
需要: apt install vim-gtk
git config --global core.editor "code --wait"
git config --global --unset core.editor
针对IntelliJ用户
当我尝试进行git rebase时,出现了以下错误: “提示:等待您的编辑器关闭文件... code -n -w: code: command not found error: There was a problem with the editor 'code -n -w'。”
当我尝试将IntelliJ与Git关联起来时,同样出现了相同的错误:
问题在于我没有将code命令添加到环境PATH变量中。而且我不想从终端使用Visual Studio Code。这就是为什么会提示“command not found”的原因。我通过从我的.gitconfig文件的核心部分中删除
editor = code -n -w
解决了这个问题。Git再次正常工作。
这将在您想要编辑提交时打开Textmate编辑器。 需要安装Textmate命令行工具。
git config --global core.editor "mate -w"
git config --global core.editor "/usr/local/bin/mate -w"
- trungly创建一个名为“k.sh”的文件,添加以下文本并放置在您的主目录(~)中:
winpty "C:\Program Files (x86)\Kinesics Text Editor\x64\k.exe" $1
git config --global core.editor ~/k.sh