【问题标题】:Error related to editor when running git commit?运行 git commit 时与编辑器相关的错误?
【发布时间】:2015-04-02 09:08:40
【问题描述】:

运行 Git 提交时出现以下错误:

c:/Program/ Files/ /(x86/)/Notepad++/notepad++.exe: -c: line 0: syntax
 error near unexpected token `('
c:/Program/ Files/ /(x86/)/Notepad++/notepad++.exe: -c: line 0: `c:/Pr
ogram/ Files/ /(x86/)/Notepad++/notepad++.exe \$@\'
error: There was a problem with the editor 'c:/Program/ Files/ /(x86/)
/Notepad++/notepad++.exe'.
Please supply the message using either -m or -F option.

这是什么意思?我该如何解决?

【问题讨论】:

    标签: git git-commit


    【解决方案1】:

    我刚刚遇到这个问题,发现你的问题试图弄清楚。我也认为 .gitconfig 中的空格和括号需要转义字符,但显然不需要。这句话对我有用:

    editor = C:/Program Files (x86)/Notepad++/notepad++.exe
    

    这是通过以下命令在我的 .gitconfig 文件中创建的:

    git config --global core.editor /c/Program\ Files\ \(x86\)/Notepad\+\+/notepad\+\+.exe
    

    我必须删除无效行,然后才能使用上述命令进行设置。

    不幸的是, git commit 仍然没有工作。在它周围添加引号和单引号终于奏效了,在我正在运行的 Notepad++ 窗口中启动 COMMIT_EDITMSG:

    editor = "'C:/Program Files (x86)/Notepad++/notepad++.exe'"
    

    平台是 Windows 8.1 Pro x64,MINGW64/Bash shell,从https://git-scm.com Windows 客户端安装。

    【讨论】:

    • 单引号内双引号是这个用例的一个很好的提示。
    • 我认为没有必要。双引号似乎包含传递给编辑器的任何参数,而单引号传递带有空格的编辑器路径。如果没有任何参数,双引号和单引号仍然是它工作所必需的。但是,git 无法正确识别我何时保存并关闭了备忘录文件,并认为它是空白的,从而使提交无效。我发现在结束单引号和双引号之间添加-multiInst -notabbar -nosession 可以解决此问题,启动一个新窗口,在关闭时可以识别。
    【解决方案2】:

    看起来 gitconfig 中的 prepare-commit-msg 钩子或 editor 选项有错字。你打电话给c:/Program/ Files/ /(x86/)/Notepad++/notepad++.exe,但你应该打电话给c:/Program\ Files\ \(x86\)/Notepad++/notepad++.exe(使用反斜杠来转义空格和括号,而不是斜杠)

    【讨论】:

      猜你喜欢
      • 2018-09-03
      • 1970-01-01
      • 2023-04-10
      • 2021-11-21
      • 1970-01-01
      • 1970-01-01
      • 2019-02-11
      • 2023-03-15
      • 1970-01-01
      相关资源
      最近更新 更多