在更新 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:06:38  来源:igfitidea点击:

Using vim for git commit messages broken after updating janus

macosgitvim

提问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 pullto 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 ~/.vimrcor explicitly telling gitto use the complete path to vimsolves 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:

尝试这个:

  1. Start a git committo get yourself into a vimeditor.
  2. Hit <CTRL> + Zto stop the process and drop back to the TTY
  3. Do a psand notice for your TTY (whose number you get with the ttycommand) 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
    
  4. Get back to your vim process with fg %1(or what ever stopped job number your git commitis listed as).

  1. 开始 agit commit进入vim编辑器。
  2. 点击<CTRL> + Z以停止该过程并返回到 TTY
  3. 做一个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
    
  4. 返回到您的 vim 进程fg %1(或您git commit列出的停止工作编号)。

What that shell output tells us is...

shell 输出告诉我们的是......

  1. I was using ttys005
  2. On the TTY bashcalled gitand gitcalled vi
  3. The full path of viis /usr/bin/vi
  4. The vicommand is a symlink to vim
  5. Calling <CTRL> + Zstopped the git commitcommand and it was #1 in the job stack.
  1. 我正在使用 ttys005
  2. 在TTYbashgitgitvi
  3. 的完整路径vi/usr/bin/vi
  4. vi命令是一个符号链接vim
  5. 调用<CTRL> + Z停止了git commit命令,它在作业堆栈中排名第一。

So, vi is the same command as vim?!?!Yes, but vimnotices that its argv[0]was viand 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/vimdoesn't work, try without the --globalflag. I could get it to work only without the --globalflag.

如果由于某种原因git config --global core.editor /usr/bin/vim不起作用,请尝试不使用--global标志。我只能让它在没有--global标志的情况下工作。