如何使用VS Code修复git commit错误"等待编辑器关闭文件..."?

AGT*_*AGT 20 git git-commit visual-studio-code

我正在努力git commit,Git正在传达这样的信息:

提示:等待你的编辑器关闭文件.../c/Users/AGT/AppData/Local/Programs/Microsoft VS Code/bin/code:第28行:/Code.exe:没有这样的文件或目录错误:有是编辑'代码 - 等'的问题.请使用-m或-F选项提供消息.

我正在使用或尝试将VS Code作为默认设置,并且在打开或关闭时我收到了相同的消息.通过VS Code或命令完成的提交git commit -m "Initial commit"工作正常.
我试过更改配置路径:

  • 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" 以及后面的变体(这些更改时出现错误消息"在寻找匹配时意外的EOF"):
  • 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

根本没有成功.

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
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题,git commit通过Git BASH命令可以正常使用Vs Code?这似乎是路径问题.

更新信息:我测试git commit了Sublime 3,它运行正常.

tym*_*tam 18

您是否已确认code可以从执行git命令的命令行访问它?

你可以跑 code --version

顺便说一句。执行时,where code我得到C:\Program Files\Microsoft VS Code\bin\code-它不再安装在%App_Data%文件夹中。但是,如果仅指定code --wait不带路径,则这无关紧要。

换句话说,这是我要尝试的过程:

  1. code --version在您用于的控制台中确认工程git
  2. git config --global core.editor "code --wait"
  3. 更改分支中的内容,然后更改git commit。VS Code是否启动并显示COMMIT_EDITMSG文件?在此处输入图片说明

  • 非常感谢,您该死,我只是再次尝试了引号,但仍然有效。很奇怪,因为我虽然在问题中说的是带引号的命令,但是它没有用。`git config --global core.editor“'C:\ Users \ AGT \ AppData \ Local \ Programs \ Microsoft VS Code \ Code.exe'-n -w” (4认同)
  • 如果您使用的是 Mac,并且无法从 CLI 访问“code”,则需要将其安装在 PATH 中:https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command -线 (3认同)
  • 嗨 tymtam,感谢您的关注。我仍然收到我的问题的第一条错误消息。VS Code 并不是你的照片。这里我得到了你推荐的内容:`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` (2认同)
  • 当我在寻找类似的问题时,我已经阅读了有关 VS Code 不再安装在 App 文件夹中的信息,尽管如此,当我尝试重新安装它时,默认文件夹是 App。我尝试在 Program Files 上重新安装,但遇到了同样的错误,唯一的区别是路径已更改。`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` (2认同)
  • 你需要在你的路径周围加上引号,你很好:) (2认同)

sch*_*itz 11

将编辑器的名称用双引号引起对我的错误。将编辑器的名称放在单引号中,例如:

git config --global core.editor'vi'

或者,如果您已经在使用单引号,请尝试切换到双引号。


Anu*_*rya 8

git config --global core.editor /usr/bin/vim 为我解决了。

  • 在 Mac OS 上收到此消息,您的答案就是我正在寻找的内容,谢谢:) (2认同)

Dan*_*cki 5

对于使用 Atom 作为 Git 相关内容的默认编辑器的人

当 Atom 是它的默认代码编辑器时,Atom 和 Visual Studio Code 之间存在某种冲突。在 Visual Studio Code 中打开终端并点击git config --global core.editor "code --wait"解决了问题。然后,每次我在控制台中执行某些操作时,Visual Studio Code 都会打开一个新选项卡,而不会崩溃。