124

I'm trying just git commit and Git is giving this message:

hint: Waiting for your editor to close the file... /c/Users/AGT/AppData/Local/Programs/Microsoft VS Code/bin/code: line 28: /Code.exe: No such file or directory error: There was a problem with the editor 'code --wait'. Please supply the message using either -m or -F option.

I'm using, or trying it, VS Code as default and I got this same message with it opened or closed. Commits done through VS Code or by command git commit -m "Initial commit" works fine.
I tried change config path with:

  • git config --global core.editor "code --wait"
  • git config --global core.editor "'C:\Users\AGT\AppData\Local\Programs\Microsoft VS Code\Code.exe' -n -w" and the followed variants(these with this change at error message "unexpected EOF while looking for matching"):
  • C:\Users\AGT\AppData\Local\Programs\Microsoft VS Code\bin
  • C:\Users\AGT\AppData\Local\Programs\Microsoft VS Code\bin\code
  • C:\Users\AGT\AppData\Local\Programs\Microsoft VS Code\Code.exe

No success at all.

The git status is:

    On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   css/app.css
        new file:   index.html
        new file:   js/app.js

How can I fix that to git commit command through Git BASH works fine with Vs Code? It's seems path issue.

Update info: I tested git commit with Sublime 3 and it works fine.

Venkataraman R
  • 12,181
  • 2
  • 31
  • 58
AGT
  • 1,343
  • 2
  • 8
  • 10
  • How did it go? Have you tried the steps in the answer below? – tymtam Sep 07 '18 at 06:17
  • I'm getting a similar message while using neovim as default editor. – Immanuel Weihnachten Jul 03 '20 at 09:45
  • 2
    In fact, I had a more general problem: the neovim process would hang upon exiting while saving the file. The issue seems due to the [gutentags](https://github.com/ludovicchabant/vim-gutentags) plugin. So, if you arrived here because you are getting the `Waiting for your editor to close the file…` message when exiting neovim after editing your commit message, you could try removing gutentags. – Immanuel Weihnachten Jul 03 '20 at 10:36

13 Answers13

113

Have you confirmed that code is accessible from the command line where you execute git commands?

You could run code --version

BTW. When I execute where code I get C:\Program Files\Microsoft VS Code\bin\code - it's no longer installed in the %App_Data% folder. However, this should be irrelevant if you only specify code --wait without the path.

In other words, here is the procedure I would attempt:

  1. Confirm code --version works in the console you use for git
  2. git config --global core.editor "code --wait"
  3. Change things in you branch and then git commit. Does VS Code start and show COMMIT_EDITMSG file? enter image description here
ouflak
  • 2,458
  • 10
  • 44
  • 49
tymtam
  • 31,798
  • 8
  • 86
  • 126
  • 2
    Hi tymtam, thanks for your attention. I still got the first error message of my question. VS Code didn't start as your pic. Here what I got with what you recommended: `code --version /c/Users/AGT/AppData/Local/Programs/Microsoft VS Code/bin/code: line 28: /Code.exe: No such file or directory` `$ where code C:\Users\AGT\AppData\Local\Programs\Microsoft VS Code\bin\code C:\Users\AGT\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd` – AGT Sep 07 '18 at 19:07
  • 2
    When I was looking about similar issues I've read about VS Code no longer installed in the App folders, despite of that when I tried reinstall it the default folder is App. I tried reinstall at Program Files and I got the same error, the only differences are the Path changed. `code --version /c/Program Files/Microsoft VS Code/bin/code: line 28: /Code.exe: No such file or directory` `where code C:\Program Files\Microsoft VS Code\bin\code C:\Program Files\Microsoft VS Code\bin\code.cmd` – AGT Sep 07 '18 at 19:41
  • 2
    You need to put quotation marks around your paths and you're good :) – tymtam Sep 10 '18 at 02:17
  • 12
    Thanks a lot, you damn right, I just tried again paying close attention at quotation marks and it works. Weird, because I though I did the same command with quotation marks as I said in my question and it wasn't working. `git config --global core.editor "'C:\Users\AGT\AppData\Local\Programs\Microsoft VS Code\Code.exe' -n -w"` – AGT Sep 10 '18 at 23:13
  • 2
    If you're on a Mac, and `code` is not accessible from the CLI, you need to install it in PATH: https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line – Nikita R. Dec 11 '22 at 22:27
  • I strongly suggest using VS Code editor for git commands together with GitHub Lens Extension installed. It provides a graphic interface for various command line operation that will speed up your process ie. interactive squash – imvanzen Mar 27 '23 at 13:35
  • On Windows it can be necessary to call `code.cmd --wait` instead of just `code --wait`. – eddex Apr 17 '23 at 10:30
52

Putting the name of the editor in double quotes produced this error for me. Put the name of the editor in single quotes, like:

git config --global core.editor 'vi'

Or, try switching to double quotes if you're already using single quotes.

schulwitz
  • 1,651
  • 1
  • 13
  • 19
50

git config --global core.editor /usr/bin/vim solved it for me.

Anupam Maurya
  • 1,927
  • 22
  • 26
4

For people having Atom as default editor for Git-related stuff

When Atom was a default code editor for it, there was some kind of conflict between Atom and Visual Studio Code. Opening a Terminal in Visual Studio Code and hitting git config --global core.editor "code --wait" solved the problem. Then Visual Studio Code opened a new tab each time I was doing something in the console without crashing.

Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94
3

Any file may be opened in any editor. So run "ps -ax|grep vim" to check which file is opened in which editor. And then run kill id-of-editor . For e.g. "kill 12345" Thats all

m yadav
  • 1,783
  • 2
  • 11
  • 13
2

If your in vs code go to your source control tab on the left

then type in your comment, press ctrl & enter

if you do git status it should say nothing to commit, working tree clean..that means it worked

Linguistics
  • 139
  • 1
  • 5
  • 2
    when `code --version` entered in the bash prompt /c/Program Files/Microsoft VS Code/Code.exe: Permission denied message comes, any solution for this ? – Sanjeewa Jan 19 '19 at 12:45
1

It is expecting you to enter the comments regarding the commit you are making enter comment and it should commit the code.

Vijai
  • 19
  • 1
1

Maybe this might help someone

For me, i forgot to add vscode to path after re-installing.

To add a file or folder to a path, follow these steps:

search for varibles => Enviornment variables => path => edit => paste the full path to file or folder or hit browse and select the path => click ok and exit.

shaderone
  • 408
  • 9
  • 21
1

I had a similar issue. For me, I had to remove quotes. This is VsCode in Windows 11 environment.

I opened my git config --global file directly

This was what I had and it did not work:

[merge]
  tool = vscode
[mergetool "vscode"]
  cmd = "code --wait $MERGED"

I changed it to this and it now works correctly:

[merge]
  tool = vscode
[mergetool "vscode"]
  cmd = code --wait $MERGED
1

Strange but updating VS Code solved the issue easily for me. Hope this helps someone trying to engineer a solution without first trying the "have you tried turning it on and off?".

Ahmed
  • 11
  • 2
0

I got that error while i configured with Atom.

I got it solved by opening the app in background before executing the command git commit

You can also try using $ git commit -m "Initial commit" It directly passes the message without waiting for the editor to open NOTE: You wont be able to add description just a comment

0

It looks like it has to do with the path of VS Code in your case and possibly the command to set the editor git config --global core.editor "code --wait" not being correct.

In my case, I couldn't complete a merging command.

What really worked for me after ensuring that VS Code is correctly setup :

code --version

worked fine. Executing where code showed me that the installation of code was in a different location than the local app data, which was where git was looking in. I could also tell code could not really be found because the editor was not launching when I was merging.

Finally executing

git config --global core.editor 'code --wait'

did the trick for me. Not that it's in single quotes as suggested further up in one of the comments.

stevosteve
  • 11
  • 1
0

for the remote development, i needed to remove the remote VSCode binaries. although it is not ideal to remove them, VSCode remote have some issues with that. VSCode re-installs them when you re-connect (settings not affected).

rm -r ~/.vscode-server/bin/
yasin_alm
  • 152
  • 1
  • 12