简体   繁体   English

疑难解答:如何让 Git 在提交时使用 VS Code?

[英]Troubleshooting: How can I get Git to use VS Code when making a commit?

I recently installed Oh My Zsh and VS code.我最近安装了 Oh My Zsh 和 VS 代码。 Whenever I enter git commit it doesn't open up code, instead it displays the following error message:每当我输入git commit时,它都不会打开代码,而是显示以下错误消息:

hint: Waiting for your editor to close the file... error: cannot run code: No such file or directory
error: unable to start editor 'code'
Please supply the message using either -m or -F option.

I am able to just run code by entering code in the terminal.我可以通过在终端中输入code来运行代码。


Steps taken:采取的步骤:

I've added the following line to my.zshrc我已将以下行添加到 my.zshrc

# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)
plugins=(... vscode)

I've run this line:我已经运行了这条线:

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

I've added these lines in my settings.json in Code我在我的 settings.json 中添加了这些行代码

    "terminal.external.osxExec": "iTerm.app",
    "terminal.explorerKind": "external",
    "terminal.integrated.shell.osx": "/bin/zsh",
    "terminal.integrated.shell.linux": "/bin/zsh"
}

What am I missing?我错过了什么? Thanks!谢谢!

Based on your output, which is:基于您的 output,即:

error: cannot run code: No such file or directory

code is not available in your $PATH environment variable. code在您的 $PATH 环境变量中不可用。 That can be easily solved:这很容易解决:

  1. CTRL+SHIFT+P in VSCode (or CMD+SHIFT+P on Mac) -- this opens the Command Palette. VSCode 中的 CTRL+SHIFT+P(或 Mac 上的 CMD+SHIFT+P)——这将打开命令面板。
  2. Type something like "code path", or the exact command you want to execute, which is: Shell Command: Install 'code' command in PATH.键入“代码路径”之类的内容,或者您要执行的确切命令,即: Shell Command: Install 'code' command in PATH.

And done, that should do the trick.完成了,这应该可以解决问题。

Specific to Zsh, my .zshrc file also has this line:具体到 Zsh,我的.zshrc文件也有这一行:

export EDITOR="code -w"

But this might not be relevant in the context of Git, it's useful for other binaries that use VSCode as editor.但这可能与 Git 的上下文无关,它对于使用 VSCode 作为编辑器的其他二进制文件很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎样才能在 git 中获取文件的每次提交的代码行 - How can i get the line of code per commit for a file in git 当我在 vs 代码内外使用 git bash 提交时如何在新窗口中打开 vs 代码 - How to open vs code in a new window when i commit with git bash outside and inside of vs code 提交时如何获得 git 提交消息? - How can I get git commit message when I commited? 如何使用 VS Code 修复 git 提交错误“正在等待您的编辑器关闭文件...”? - How can I fix git commit error "Waiting for your editor to close the file..." with VS Code? Git pre-commit hook:如何在使用 -a 标志提交时获取添加/修改的文件 - Git pre-commit hook:How can I get added/modified files when commit with -a flag 我如何从git压缩的提交中获取最后的提交 - How can i get the last commit from squashed commit in git 如何从VS / msbuild中提取Git提交哈希? - How can I extract Git commit hash from VS/msbuild? 如何使用 shell function 在我的 git 预提交挂钩中使用 husky 返回代码? - How can I use a shell function with a return code in my git pre-commit hook using husky? 签署提交时如何阻止 git 使用 GUI PGP 密钥管理器? - How can I stop git from use of GUI PGP key manager when signing a commit? 如何配置 Visual Studio 代码以在保存时提交到 git? - How can I configure visual studio code to commit to git on save?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM