我如何修复 git 提交错误“等待您的编辑器关闭文件...”与 VS 代码?

我正在尝试 git commit,Git 给出了这样的信息:

提示: 等待编辑器关闭文件..。 /c/Users/AGT/AppData/Local/Programs/Microsoft VS Code/bin/Code: line 28:/Code.exe: 没有这样的文件或目录错误: 有一个问题 请使用以下任一选项提供消息: - M 还是 F 选项。

我正在使用,或尝试它,VS 代码作为默认,我得到了这个相同的消息与它打开或关闭。通过 VS 代码或通过命令 git commit -m "Initial commit"完成的提交可以正常工作。
我尝试用以下方法更改配置路径:

  • git config --global core.editor "code --wait"
  • Git config —— global core.Editor ”‘ C: 用户 AGT AppData 本地程序 Microsoft VS Code Code.exe’-n - w” 和后面的变体(这些变体在错误消息“当查找匹配时意外的 EOF”中有此更改) :
  • 用户 AGT AppData 本地程序 Microsoft VS 代码仓
  • 用户 AGT AppData 本地程序 Microsoft VS 代码箱代码
  • 用户 AGT AppData 本地程序 Microsoft VS Code Code.exe

一点都不成功。

Git 的状态是:

    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

我如何通过 Git BASH 修复 git commit命令在 VS 代码中运行良好? 这似乎是路径问题。

更新信息: 我用升华3测试了 git commit,它工作得很好。

159308 次浏览

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

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

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.

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

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.

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

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

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.

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

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.

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

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

OK in any terminal, but not Git bash

On windows 10, I have the same problem, hapenning only in git bash, even after reinstalled and reconfigured. Do I miss some config files to delete... ?

ex. when running "git commit" and waiting for editor:

hint: Waiting for your editor to close the file... code -w: line 1: code: command not found
error: There was a problem with the editor 'code -w'.
Please supply the message using either -m or -F option.

When running the same command (git commit) in a standard terminal, VS code opens.

VS Code window