125

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.

3
  • How did it go? Have you tried the steps in the answer below?
    – tymtam
    Sep 7, 2018 at 6:17
  • I'm getting a similar message while using neovim as default editor. Jul 3, 2020 at 9: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 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. Jul 3, 2020 at 10:36

14 Answers 14

115

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
7
  • 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 7, 2018 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 7, 2018 at 19:41
  • 2
    You need to put quotation marks around your paths and you're good :)
    – tymtam
    Sep 10, 2018 at 2: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, 2018 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: code.visualstudio.com/docs/setup/…
    – Nikita R.
    Dec 11, 2022 at 22:27
53

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

3
  • 2
    got this message on Mac OS and your answer is what I was searching for, thanks :)
    – Sergii
    Dec 14, 2020 at 16:35
  • If you installed vim via homebrew, it'll be /usr/local/bin/vim. This is what worked for me.
    – Matt Rose
    Oct 27, 2021 at 16:13
  • Thanks for this answer. It helped me resolve this issue Jan 25, 2022 at 13:38
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.

2
  • 1
    If the editor has spaces in the path, put it in both single quotes (inner) and double quotes (outer). Aug 18, 2021 at 20:24
  • Alternatively, git config --global core.editor 'vim' Jun 28 at 16:20
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.

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

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

1
  • 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, 2019 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.

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.

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

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.

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/
0

I had a similar issue where I was attempting to set Notepad as the default editor. Apparently you have to add single quotes around the double quoted path, like: git config --global core.editor '"C:\\Windows\\System32\\notepad.exe"'

To be honest, I don't actually remember how many backslashes I've used to get the path right, but it currently looks like the following in the gitconfig file (located in C:\Users\user):

[core]
    editor = \"C:\\Windows\\System32\\notepad.exe\"

System: Windows 10, and Powershell opened from Windows Terminal.

EDIT: I tested setting up VS Code as the editor with git config --global core.editor "code --wait" and ended up with the same problem as the OP. I then tried the full path to the program with the double and single quotes, as described earlier, and now it worked: git config --global core.editor '"c:\\Users\\Ian\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"'

Currently, the gitconfig file looks like this:

[core]
    editor = \"c:\\\\Users\\\\Ian\\\\AppData\\\\Local\\\\Programs\\\\Microsoft VS Code\\\\Code.exe\" 

so I'm not entirely sure how the escaping thing works.

New contributor
Ian is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Sep 27 at 2:18

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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.