【问题标题】:Troubleshooting: How can I get Git to use VS Code when making a commit?疑难解答:如何让 Git 在提交时使用 VS Code?
【发布时间】:2020-08-15 05:35:54
【问题描述】:

我最近安装了 Oh My Zsh 和 VS code。每当我输入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.

我可以通过在终端中输入code 来运行代码。


采取的步骤:

我已在我的 .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)

我已经运行了这一行:

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

我已在代码的 settings.json 中添加了这些行

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

我错过了什么?谢谢!

【问题讨论】:

    标签: git visual-studio-code terminal zsh iterm2


    【解决方案1】:

    根据您的输出,即:

    error: cannot run code: No such file or directory
    

    code 在您的 $PATH 环境变量中不可用。这很容易解决:

    1. VSCode 中的 CTRL+SHIFT+P(或 Mac 上的 CMD+SHIFT+P)——这将打开命令面板。
    2. 键入“代码路径”之类的内容,或者您​​要执行的确切命令,即:Shell Command: Install 'code' command in PATH.

    完成了,这应该可以解决问题。

    特定于Zsh,我的.zshrc文件也有这一行:

    export EDITOR="code -w"
    

    但这可能与 Git 的上下文无关,它对使用 VSCode 作为编辑器的其他二进制文件很有用。

    【讨论】:

      猜你喜欢
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-06
      • 2014-08-29
      • 2011-10-27
      相关资源
      最近更新 更多