经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » C# » 查看文章
Git使用之设置编辑器
来源:cnblogs  作者:蛮哥哥  时间:2018/11/17 15:01:13  对本文有异议

使用VIM编辑commit注释信息

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

完成注释后需要退出:

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

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

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

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

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

修改默认编辑器

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


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

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

设置成功会如下显示。

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

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

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


将默认编辑器修改为VS Code

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

设置成功会如下显示。

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


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

  1. $ git commit
  2. 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

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

For atom

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

For sublime

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


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

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

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

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

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

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


Ref:Aborting commit due to empty commit message

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号