配置VS Code为Git编辑器后git commit提示提交信息为空的问题
解决WSL下Git Commit时VS Code提交信息为空的问题
问题根源
WSL环境调用Windows版VS Code时,Git创建的临时提交信息文件存在跨文件系统同步问题,导致VS Code无法正确读取或保存内容;或是编辑器配置参数不兼容WSL环境。
解决方案
1. 确认VS Code在WSL中可正常调用
在WSL终端执行:
code --version
若无法返回VS Code版本号,需将VS Code的Windows路径添加到WSL的PATH中:
echo 'export PATH="$PATH:/mnt/c/Users/你的Windows用户名/AppData/Local/Programs/Microsoft VS Code/bin"' >> ~/.bashrc source ~/.bashrc
替换你的Windows用户名为实际用户名。
2. 重新配置Git全局编辑器(核心修复)
替换原有配置,添加--new-window参数确保VS Code正确关联临时文件:
git config --global core.editor "/mnt/c/Users/你的Windows用户名/AppData/Local/Programs/Microsoft VS Code/bin/code --wait --new-window"
若code命令已在WSL中可执行,也可用简化版:
git config --global core.editor 'code --wait --new-window'
3. 验证修复效果
执行git commit,此时VS Code会打开新窗口并加载Git生成的提交信息模板(含注释提示),输入提交信息后保存关闭窗口,终端即可正常完成提交。
额外排查项
- 执行
git config --global --list,确认core.editor设置无语法错误(如多余引号、转义字符)。 - 若使用VS Code Insider版本,将命令中的
code替换为code-insiders。
内容的提问来源于stack exchange,提问作者DrCaputto
相关产品推荐
相关产品推荐

