Git为何忽略我对COMMIT_EDITMSG的修改?git commit --amend执行异常
解决Git Commit Amend时VSCode不等待的问题
问题现象
已通过以下命令设置Git全局编辑器:
git config --global core.editor "code --wait"
执行git commit --amend时,VSCode会打开COMMIT_EDITMSG标签页,但Git命令直接执行完成,终端出现新提示符,编辑并关闭标签页后提交信息未更改。
解决方法
1. 检查并修正编辑器配置
先确认当前core.editor配置是否正确,执行命令:
git config --global --get core.editor
若输出不是code --wait,重新执行设置命令:
git config --global core.editor "code --wait"
2. 确保code命令已加入系统PATH
终端直接执行code --version,若无法输出VSCode版本,说明命令未注册到环境变量:
- Windows:打开VSCode,按
Ctrl+Shift+P,输入Shell Command: Install 'code' command in PATH执行 - macOS:打开VSCode,按
Cmd+Shift+P,输入Shell Command: Install 'code' command in PATH执行 - Linux:打开VSCode,按
Ctrl+Shift+P,输入Shell Command: Install 'code' command in PATH执行
3. 使用VSCode完整路径指定编辑器
如果code命令路径仍有问题,直接用可执行文件完整路径配置:
- Windows示例:
git config --global core.editor "'C:\Program Files\Microsoft VS Code\Code.exe' --wait"
- macOS示例:
git config --global core.editor "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code --wait"
- Linux示例(根据实际安装路径调整):
git config --global core.editor "/usr/bin/code --wait"
4. 验证配置有效性
执行以下命令测试编辑器是否会等待操作完成:
git config --global --edit
若VSCode打开Git配置文件,且终端会等待你关闭标签页后才返回,说明配置生效,再尝试git commit --amend即可正常修改提交信息。
内容的提问来源于stack exchange,提问作者Loren
相关产品推荐
相关产品推荐

