161

I don't often have to modify multiple commit messages, but it has happened once or twice and I don't ever remember seeing this. I hope someone else has. When I git rebase -i HEAD~7, the expected list opens in vi exactly as expected. I change the pick values to edit where appropriate and then :wq.

Could not execute editor

The core.editor setting in my global .gitconfig is vi (I've also changed it to vim in a wildly desperate move). I tried using mate, but that didn't even open the initial list properly so I changed it back.

I'm using v1.7.3 and would welcome any suggestions.

5
  • 1
    The source includes git_editor "$TODO" || die_abort "Could not execute editor". Since you say the editor does actually come up, that means it's returning a nonzero exit code. Can you replicate that behavior using it normally on the command-line?
    – Cascabel
    Nov 4, 2010 at 0:52
  • What's weird to me is that vi launches to display the list of commits, but when I save and close everything just dies. See my answer for the change I made to make it magically start working. Nov 4, 2010 at 11:26
  • What OS were you running? Running OSX Lion I had the same trouble and your answer fixed it. +1
    – Adam Lewis
    Jun 21, 2013 at 15:26
  • @AdamLewis -- I can't be sure now, but probably 10.6 or .7 given the date. OSX, for sure. Jun 21, 2013 at 15:42
  • 6
    I think I created this problem when I used homebrew to install a new vim. Setting git config --global core.editor "/usr/local/bin/vim" fixed it for me.
    – mmell
    Nov 10, 2014 at 21:18

14 Answers 14

188

Yesterday was just one of those days. On a lark, I decided to set the full path to vi (e.g. /usr/bin/vi) rather than just the executable. Now everything works. I have to admit that I don't get it since vi is perfectly executable on its own (my $EDITOR env variable is also set to vi), but it's working and my technical karma hasn't been so great lately so maybe I just shouldn't question the deities will...

6
  • 6
    Where did you set the full path to /usr/bin/vi ?
    – Amala
    Apr 15, 2011 at 21:57
  • 131
    I put it in my global config file: git config --global core.editor "/usr/bin/vim". Apr 15, 2011 at 23:19
  • I had the same issue. For reasons I can't fathom, my core.editor setting was set to /user/bin/vim rather than /usr/bin/vim
    – jonnybot
    Jan 8, 2014 at 16:50
  • Had the same issue but with Sublime Text - full path finally solved things. Which was weird because i'm sure its all worked fine before anyway... :-\
    – Hal
    May 30, 2014 at 2:43
  • git config --global color.editor "/usr/local/bin/vim" did worked for me :) , thanks
    – przbadu
    Mar 9, 2016 at 3:31
163

The following command

git config --global core.editor /usr/bin/vim

fixes it.

[edit]

Now I see that someone already posted it in the comments. Hope its still helpful for some blind folks like me.

2
  • 6
    For Windows for example (missing single quotes, were my problem): git config --global core.editor "'C:\Program Files (x86)\Vim\vim74\vim.exe'"
    – chrjs
    Apr 27, 2015 at 13:37
  • 1
    Yes, this ^. To clarify this, use double quotes around single quotes around the path to the executable.
    – Jacob
    Mar 17, 2016 at 21:08
7

Unlike with the other answers here so far, for me using the absolute path to vi, and setting the git core.editor config, were not sufficient to solve the problem. (Those were already in place.)

In my situation, the problem was solved by adding the -f flag to the vi command:

git config --global core.editor '/usr/bin/vi -f'

Once this -f option is in place, I can use git rebase -i, and when I save-and-exit the commit list, the rebase proceeds as it should instead of giving the "could not execute editor" error.

The vim man page says with regard to option -f,

For the GUI version, Vim will not fork and detach from the shell it was started in. ... This option should be used when Vim is executed by a program that will wait for the edit session to finish (e.g. mail).

Well I'm not using a GUI version, that I know of. I'm running git at the bash command line in a terminal window on masOS Sierra 10.12.6. But since git rebase -i waits for the edit session to finish, I suppose that's why the -f option is necessary here. Maybe vim (without -f) tries to fork/detach from the shell for some reason I haven't been able to figure out.

0
6

I had this issue, and it was caused by some part of the vcscommand plugin for vim. Starting vim with any of these commands resulted in exit code 1 ("error"):

  • vi
  • vim

But these gave me exit code 0 ("success"):

  • /usr/bin/vi
  • /usr/bin/vim
  • vi -u NONE
  • vim -u NONE

I was able to trace it back to the specific plugin by disabling ~/.vimrc and files in ~/.vim by renaming them and running vi -c q ; echo $? to quickly run vim and print the exit code.

2
  • 1
    I had the same problem and setting the full path to vim worked: git config --global core.editor /usr/bin/vim
    – James
    Aug 29, 2011 at 22:47
  • Another possible culprit seems to be the pathogen plugin on Mac OS X.
    – sschuberth
    Jan 15, 2013 at 13:42
3

For me, it was a problem with my .vimrc. Temporarily renaming that file fixed it. Followed by debugging my .vimrc. This is very similar to ignu's experience.

1
  • Yeah, I had !silent colorscheme macvim in my .vimrc, to set the colorscheme to that if it existed, and to not bug me if it didn't (so the command line vim would work). On the other hand, that changed the exit status to 1 when it failed, even with silent!.
    – Max
    Mar 20, 2014 at 19:26
3

If you wanted to for whatever reason use sublime you could do something like the following in your global config file:

 git config --global core.editor "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"
1

It just took me a while to track down my problem to one of my plugins.

(specifically, it was https://github.com/ervandew/supertab)

I guess that's the downside to automatically updating all my plugins.

So best advice, disable half your vimrc and plugins. If that doesn't help, the problem's with your other half.

1
  • How did you track it down to supertab? That would be really helpful information. May 16, 2014 at 0:15
1

I was trying to squash commits as shown here https://www.youtube.com/watch?v=V5KrD7CmO4o. My git editor (notepad++) opened up in the rebasing step. But, in the amend commit message step, I saw the "Could not execute editor" issue. It probably happened because the git editor settings were wrong and also because I installed notepad++ in a non-standard location on my windows system. That is, 'git config core.editor' gave me notepad++ -multilnst- nosession.

To fix the issue, provide full path like this :

git config --global core.editor "'C:\CustomFolder\NPP\notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

Refer : https://www.youtube.com/watch?v=YLxdkcT6H4g

0

Are you sure that /usr/bin/vim was on 1.7.3? I had the same issue because I had the backup plugin installed which is only supported in 1.7.3 and for some reason /usr/bin/vim was all of a sudden downgraded to 1.7.2, perhaps because of a major update of XCode...

0

I had this problem as well when I had already had vim open for a rebase in another terminal. I had started the rebase, got interrupted, and when I came back I tried it again from scratch in the other terminal, not realizing I was in the middle of the same rebase elsewhere. Just finishing the vim rebase session in the other terminal worked fine.

0

Oddly enough, just trying it again worked for me.

My core.editor and $EDITOR variables are not set.

1
  • It only fails for me now and then, maybe 3% of the time. Seems like an intermittent bug. Did the problem return for you? Sep 1, 2020 at 17:12
0

For me, using windows: close the current terminal, and open another one(win+R, type 'cmd', then 'enter'), then it suddenly works.

0

Another option is to use nano editor.

$ whereis nano
$ git config --global core.editor path/to/nano

Fixes it.

0

VS Code solution:

git config --global core.editor "/Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.