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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52195877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:20:31  来源:igfitidea点击:

How can I fix git commit error "Waiting for your editor to close the file..." with VS Code?

gitvisual-studio-codegit-commit

提问by AGT

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

我正在尝试git commit,Git 给出了这条消息:

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.

提示:正在等待编辑器关闭文件... /c/Users/AGT/AppData/Local/Programs/Microsoft VS Code/bin/code: line 28: /Code.exe: No such file or directory 错误:有编辑器“代码 --wait”有问题。请使用 -m 或 -F 选项提供消息。

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:

我正在使用或尝试使用 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"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
  • 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

No success at all.

根本没有成功。

The git status is:

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

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

如何git commit通过 Git BASH修复该问题以在 Vs Code 中正常工作?好像是路径问题。

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

更新信息:我git commit用 Sublime 3测试过,效果很好。

采纳答案by tymtam

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

您确认code可以从执行 git 命令的命令行访问吗?

You could run code --version

你可以跑 code --version

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

顺便提一句。当我执行where code我得到C:\Program Files\Microsoft VS Code\bin\code- 它不再安装在 %App_Data% 文件夹中。但是,如果您只指定code --wait没有路径,这应该无关紧要。

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

换句话说,这是我将尝试的程序:

  1. Confirm code --versionworks 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
  1. 确认code --version在您使用的控制台中工作git
  2. git config --global core.editor "code --wait"
  3. 改变你分支中的东西,然后git commit. VS Code 是否启动并显示 COMMIT_EDITMSG 文件?enter image description here

回答by schulwitz

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'

git config --global core.editor 'vi'

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

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

回答by Linguistics

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

如果您在 vs 代码中转到左侧的源代码控制选项卡

then type in your comment, press ctrl & enter

然后输入您的评论,按 ctrl 并输入

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

如果你做 git status 它应该什么都不说提交,工作树干净......这意味着它有效

回答by Vijai

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

它希望您输入有关您正在提交的提交的注释,输入注释,它应该提交代码。

回答by Daniel Danielecki

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

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

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.

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

回答by manoj yadav

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

任何文件都可以在任何编辑器中打开。所以运行“ps -ax|grep vim”来检查哪个文件是在哪个编辑器中打开的。然后运行 ​​kill id-of-editor 。例如“杀死12345”仅此而已

回答by Swapnil Jena

I got that error while i configured with Atom.

我在配置 Atom 时遇到了这个错误。

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

我通过在执行命令之前在后台打开应用程序来解决它 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

您也可以尝试使用$ git commit -m "Initial commit"It 直接传递消息,而无需等待编辑器打开 注意:您将无法添加描述,仅添加评论

回答by Pedro Marinho

Change git committo git commit -m "Title of your update".

更改git commitgit commit -m "Title of your update"