Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using vim for git commit messages broken after updating janus

Tags:

git

vim

macos

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 :wq but instead of the commit working, I get the following error message:

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?

like image 686
Nat Ritmeyer Avatar asked Jan 30 '13 15:01

Nat Ritmeyer


People also ask

Can I use Vim with git?

Git command works in the command line interface. The vim plugin named fugitive plugin is developed by Tim pope which is used to work with the git tool without terminating the editor. So, vim and git can work together by using the fugitive plugin.

How do I fix typo in commit message?

On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter. In your text editor, edit the commit message, and save the commit.


4 Answers

After a bit of googling, it turns out that the answer is to run the following:

git config --global core.editor $(which vim)
like image 76
Nat Ritmeyer Avatar answered Oct 09 '22 09:10

Nat Ritmeyer


Nat Ritmeyer has given the right solution. I will give you the cause.

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".

Try this:

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

What that shell output tells us is...

  1. I was using ttys005
  2. On the TTY bash called git and git called vi
  3. The full path of vi is /usr/bin/vi
  4. The vi command is a symlink to vim
  5. Calling <CTRL> + Z stopped the git commit command and it was #1 in the job stack.

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.

The best solution is to tell git to use vim, but I suggest you don't assume that your vim path is the same as everyone elses (maybe you installed via brew install vim)

git config --global core.editor $(which vim)
like image 21
Bruno Bronosky Avatar answered Oct 09 '22 11:10

Bruno Bronosky


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)

like image 43
Lahiru Jayaratne Avatar answered Oct 09 '22 09:10

Lahiru Jayaratne


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:

git config --global core.editor '/usr/bin/vim -f -u NONE'
like image 40
Mr Wilde Avatar answered Oct 09 '22 09:10

Mr Wilde