Git使用之设置编辑器

使用VIM编辑commit注释信息

在命令输入模式下面,输入字母”i”,则VIM进入到插入模式,接着输入自己的注释内容;

完成注释后需要退出:

1)按键Esc,如果无效,连续按两次

2)当底部提示行出现空白时,输入冒号“:”

3)再输入字母“q”,回车 (输入wq,为保存退出)

但是实际上使用vim非常不方便,

好吧,我是在设置其他编辑器失败后没有办法才有那么几天被迫使用了vim…

修改默认编辑器

关于默认编辑器最好是安装git之前你就已经安装了响应的编辑器比如notepad++或VS Code,这样就可以在安装git的时候直接在安装配置界面中配置。如果在安装完了git后再要修改默认编辑器参照如下:


在git中设置默认使用的文本编辑器为notepad++

$ git config --global core.editor notepad++

设置成功会如下显示。

$ git config --global core.editor 
notepad++

有的时候设置不成功,提交的时候不弹出notepad++,可以再使用如下命令试试

git config --global core.editor "'D:\Notepad++\notepad++.exe' -multiInst -notabbar -nosession -noPlugin '$*'"


将默认编辑器修改为VS Code

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

设置成功会如下显示。

$ git config --global core.editor
code -w


设置了编辑器后,commit时编辑器打开了但是bash中提示提交取消

$ git commit
Aborting commit due to empty commit message.

查找到StackOverflow上说法

When you set an editor in the configuration of Git, make sure to pass the parameter "-w" to force Git to wait your commit message that you would type on your custom editor.

相应的做法是设置编辑器的时候加上-w参数

For Visual studio Code

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

For atom

git config --global core.editor "atom -w"

For sublime

git config --global core.editor "subl -w"


但是有时候即使我们加了-w参数也不成功或者说会报如下错误:

$ git config --global core.editor "Code -w"
 warning: core.editor has multiple values
 error: cannot overwrite multiple values with a single value
        Use a regexp, --add or --replace-all to change core.editor.

这个时候需要重置git的编辑器设置然后重新设置编辑器

git config --global --unset-all core.editor
git config  --unset-all core.editor
git config --global core.editor "code -w"

这样操作之后终于把问题解决了,设置成功后提交时会提示如下:

$ git commit
hint: Waiting for your editor to close the file...


Ref:Aborting commit due to empty commit message

猜你喜欢

转载自www.cnblogs.com/lyh523329053/p/9968384.html