我正在试用Windows上的Git。我到了尝试“git commit”的地步,我得到了这个错误:

终端是哑的,但没有视觉也 编辑器定义。请提供 消息使用-m或-F选项。

所以我发现我需要一个叫做EDITOR的环境变量。没有问题。我把它设置为指向记事本。这几乎奏效了。默认的提交消息在记事本中打开。但是记事本不支持换行。我出去得到了notepad++,但我不知道如何将notepad++设置为%EDITOR%,使其与Git正常工作。

我没有嫁给notepad++。在这一点上,我不介意我使用什么编辑器。我只是希望能够在编辑器中而不是在命令行中输入提交消息(使用-m)。

那些在Windows上使用Git的人:你使用什么工具来编辑你的提交消息,你必须做什么才能让它工作?


当前回答

我的PortableGit 1.6运行良好,但在升级到PortableGit 1.7 Windows版本后,我遇到了一些问题。有些Git命令可以打开notepad++ .exe,但有些不能,尤其是Git rebase的行为不同。

问题是有些命令运行Windows的cmd进程,有些命令使用Unix的cmd进程。我想给启动属性notepad++编辑器,所以我需要有一个自定义脚本。我的解是这个。

Create a script to run an appropriate text editor. The script looks weird, but it handles both the Windows and Unix variation. c:/PortableGit/cmd/git-editor.bat #!/bin/sh # Open a new instance function doUnix() { "c:\program files\notepad++\notepad++.exe" -multiInst -nosession -notabbar $* exit } doUnix $* :WINCALL "c:\program files\notepad++\notepad++.exe" -multiInst -nosession -notabbar %* Set the global core.editor variable The script was saved to git/cmd folder, so it's already in a gitconsole path. This is mandatory as a full path may not work properly. git config --global core.editor "git-editor.bat"

现在我可以运行git commit -a和git rebase -i master命令。如果你在Git Windows工具中遇到问题,可以尝试一下。

其他回答

如果路径中有空格,Git似乎无法找到编辑器。因此,您必须将Patrick回答中提到的批处理文件放到非空白路径中。

Vim/gVim很适合我。

>echo %EDITOR%

c:\Vim\Vim71\vim.exe

这招对我很管用:

将包含编辑器可执行文件的目录添加到PATH变量中。(如。"C:\Program Files\Sublime Text 3\") 重新启动计算机。 改变核心。将编辑器可执行文件的名称改为不带'.exe'扩展名的全局Git变量(例如Git config——global core. exe)。编辑器sublime_text)

就是这样!

注意:Sublime Text 3是我在这个例子中使用的编辑器。

我在Windows上使用Cygwin,所以我使用:

export EDITOR="emacs -nw"

-nw代表无窗口,即告诉Emacs不要尝试使用X窗口。

Emacs键绑定不能从Windows shell中为我工作,所以我只会从Cygwin shell中使用这个…(建议使用rxvt)

我设法通过使用引号和/设置编辑器变量来获得环境版本:

EDITOR="c:/Program Files (x86)/Notepad++/notepad++.exe"