修复Mac下命令行Git无法在vi中commit的错误-- here was a problem with the editor 'vi'.

本文介绍了解决Git在使用Vi编辑器时出现错误的问题。通过调整Vi配置文件及指定使用特定路径下的Vi版本,可以有效避免Git提交时遇到编辑器退出异常的情况。


在命令行使用git commit进入VI编辑注释的时候,保存退出,给出以下提示,以前还好好的,忽然就不正常了‘

错误提示如下

error: There was a problem with the editor 'vi'.
Please supply the message using either -m or -F option.


出问题了就上搜索引擎,得到两篇文章,搞定

原文1:http://tooky.co.uk/2010/04/08/there-was-a-problem-with-the-editor-vi-git-on-mac-os-x.html

原文2:http://www.phpvim.net/app/vim/fix-issue-there-was-a-problem-with-editor-vim.html

I have had an annoying problem with git and vi. I like to use vim to edit my commit messages, but I’ve been hit with this annoying message every time I write the message and quit vim.

error: There was a problem with the editor 'vi'
After a little bit of digging I found that this message is shown by git when the editor exits with a non-zero exit code. You can use $? to see the exit code of last script or application.

$ vim     # then exit vim with :q immediately
$ echo $?
1
I’m still not sure why vim is exiting with non-zero exit code, but it is definitely related to my .vimrc - moving it to .vimrc.bak seemed to fix the problem. I’m using the excellent pathogen plugin to manage my vimfiles, so I plan to go through that and my installed plugins to find the cause of the problem.

There is a fix though, I’m not sure what’s causing this, but I found a post on the vim-mac mailing list which shows this:

$ vim          # and exit with :q
$ echo $?
1
$ /usr/bin/vim # and exit with :q
$ echo $?
0
$ which vim
/usr/bin/vim
Running vim with /usr/bin/vim seems to make it exit cleanly. So to fix the problem with git commit you just need to run this:

$ git config --global core.editor /usr/bin/vim
I’d still like to get to the root of the problem, but this gets me my git commit messages back!





评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值