在更新 janus 后使用 vim 处理 git commit 消息中断
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14607584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using vim for git commit messages broken after updating janus
提问by Nat Ritmeyer
After updating the janus vim distribution there appears to be a problem with using vim for commit messages. The best example of this is when doing a git pull
to get someone else's changes. The vim editor is displayed, I type my commit message, I enter :wqbut instead of the commit working, I get the following error message:
更新 janus vim 发行版后,使用 vim 提交消息似乎存在问题。最好的例子是在执行 agit pull
以获取其他人的更改时。显示了 vim 编辑器,我输入了我的提交消息,我输入了:wq但是提交没有工作,我收到以下错误消息:
error: There was a problem with the editor 'vi'.
Not committing merge; use 'git commit' to complete the merge.
I then have to manually commit :(
然后我必须手动提交:(
How do I get git to play nicely with vim?
我如何让 git 与 vim 一起玩得很好?
回答by Nat Ritmeyer
After a bit of googling, it turns out that the answer is to run the following:
经过一番谷歌搜索,结果是运行以下命令:
git config --global core.editor $(which vim)
回答by Bruno Bronosky
Nat Ritmeyer has given the right solution. I will give you the cause.
Nat Ritmeyer 给出了正确的解决方案。我会告诉你原因。
As Steve Tooke explained, hiding your ~/.vimrc
or explicitly telling git
to use the complete path to vim
solves the problem. However, he ends with "I'd still like to get to the root of the problem".
正如Steve Tooke 解释的那样,隐藏~/.vimrc
或明确告诉git
使用完整路径来vim
解决问题。然而,他的结尾是“我仍然想找到问题的根源”。
Try this:
尝试这个:
- Start a
git commit
to get yourself into avim
editor. - Hit
<CTRL> + Z
to stop the process and drop back to the TTY Do a
ps
and notice for your TTY (whose number you get with thetty
command) there is something like...$ tty /dev/ttys005 $ ps PID TTY TIME CMD 17547 ttys005 0:00.15 -bash 65126 ttys005 0:00.02 git commit 65127 ttys005 0:00.10 vi .git/COMMIT_EDITMSG $ which vi /usr/bin/vi $ ll /usr/bin/vi lrwxr-xr-x 1 root wheel 3 Oct 3 17:40 /usr/bin/vi -> vim $ jobs [1]+ Stopped git commit
Get back to your vim process with
fg %1
(or what ever stopped job number yourgit commit
is listed as).
- 开始 a
git commit
进入vim
编辑器。 - 点击
<CTRL> + Z
以停止该过程并返回到 TTY 做一个
ps
并注意你的 TTY(你用tty
命令得到的号码)有类似的东西......$ tty /dev/ttys005 $ ps PID TTY TIME CMD 17547 ttys005 0:00.15 -bash 65126 ttys005 0:00.02 git commit 65127 ttys005 0:00.10 vi .git/COMMIT_EDITMSG $ which vi /usr/bin/vi $ ll /usr/bin/vi lrwxr-xr-x 1 root wheel 3 Oct 3 17:40 /usr/bin/vi -> vim $ jobs [1]+ Stopped git commit
返回到您的 vim 进程
fg %1
(或您git commit
列出的停止工作编号)。
What that shell output tells us is...
shell 输出告诉我们的是......
- I was using ttys005
- On the TTY
bash
calledgit
andgit
calledvi
- The full path of
vi
is/usr/bin/vi
- The
vi
command is a symlink tovim
- Calling
<CTRL> + Z
stopped thegit commit
command and it was #1 in the job stack.
- 我正在使用 ttys005
- 在TTY
bash
叫git
和git
叫vi
- 的完整路径
vi
是/usr/bin/vi
- 该
vi
命令是一个符号链接vim
- 调用
<CTRL> + Z
停止了git commit
命令,它在作业堆栈中排名第一。
So, vi is the same command as vim?!?!Yes, but vim
notices that its argv[0]
was vi
and runs in compatible mode. This can cause problems depending on what is in your .vimrc
.
所以,vi 和 vim 是同一个命令?!?!是的,但请vim
注意它argv[0]
是vi
并在兼容模式下运行。这可能会导致问题,具体取决于您的.vimrc
.
The best solutionis to tell git to use vim, but I suggest you don't assumethat your vim path is the same as everyone elses (maybe you installed via brew install vim
)
将最好的解决办法是告诉git的使用vim,但我建议你不要以为你的VIM路径是一样的,每个人都别人的(也许你通过安装brew install vim
)
git config --global core.editor $(which vim)
回答by Mr Wilde
This could be a plugin or something in your .vimrc file. The best way to load vim in a safe mode for editing commit messages is to use:
这可能是您的 .vimrc 文件中的插件或其他内容。在安全模式下加载 vim 以编辑提交消息的最佳方法是使用:
git config --global core.editor '/usr/bin/vim -f -u NONE'
回答by Lahiru
I faced the same problem every time I fetched from remote repo and merged it with another branch.
每次从远程仓库中获取数据并将其与另一个分支合并时,我都会遇到同样的问题。
Typing this in terminal fixed it for me
在终端中输入它为我修复了它
git config --global core.editor $(which vim)
git config --global core.editor $(which vim)
回答by Aakash Jog
If for some reason, git config --global core.editor /usr/bin/vim
doesn't work, try without the --global
flag. I could get it to work only without the --global
flag.
如果由于某种原因git config --global core.editor /usr/bin/vim
不起作用,请尝试不使用--global
标志。我只能让它在没有--global
标志的情况下工作。