git - 疑难解答:如何让 Git 在提交时使用 VS Code?
问题描述
我最近安装了 Oh My Zsh 和 VS 代码。每当我输入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"
}
我错过了什么?谢谢!
解决方案
根据您的输出,即:
error: cannot run code: No such file or directory
code
在您的 $PATH 环境变量中不可用。这很容易解决:
- VSCode 中的 CTRL+SHIFT+P(或 Mac 上的 CMD+SHIFT+P)——这将打开命令面板。
- 键入“代码路径”之类的内容,或者您要执行的确切命令,即:
Shell Command: Install 'code' command in PATH.
完成了,这应该可以解决问题。
具体到 Zsh,我的.zshrc
文件也有这一行:
export EDITOR="code -w"
但这可能与 Git 的上下文无关,它对于使用 VSCode 作为编辑器的其他二进制文件很有用。
推荐阅读
- intellij-idea - 如何在.vue文件的导入中设置intellij的编辑器配置空间
- macos - 如何解决这个 Python (py2app) 代码签名问题
- java - 远程 postgres 服务器在春季导致不稳定的测试
- python - 如何使用 Python Turtle 绘制不重叠的 N 次七边形形状?
- python - 锁定默认字典的键?
- python - Python中的二进制检查器
- python - QT Designer:在尊重窗口重新缩放 PyQT5 的同时移动和调整小部件的大小
- python - random.choice 总是返回 false
- java - Selenium 中的 WebDriverManager
- javascript - 想创建一个google chrome扩展来高亮文本,当我们使用chrome查看本地html文件的时候