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

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

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

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

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


当前回答

我正在使用GitHub for Windows,这是一个很好的可视化选项。但我也更喜欢命令行,所以当我在Git shell中打开一个存储库时,我只需要设置以下内容:

git config --global core.editor vim

这很有效。

其他回答

以下是Cygwin的解决方案:

#!/bin/dash -e
if [ "$1" ]
then k=$(cygpath -w "$1")
elif [ "$#" != 0 ]
then k=
fi
Notepad2 ${k+"$k"}

如果没有路径,则不传递路径 如果path为空,则传递空路径 如果path不为空,请转换为Windows格式。

然后我设置这些变量:

export EDITOR=notepad2.sh
export GIT_EDITOR='dash /usr/local/bin/notepad2.sh'

编辑器允许脚本与Git一起工作 GIT_EDITOR允许脚本使用Hub命令

这是我使用Geany作为Git编辑器的设置:

git config --global core.editor C:/path/to/geany.bat

geany.bat中包含以下内容:

#!/bin/sh
"C:\Program Files\Geany\bin\Geany.exe" --new-instance "$*"

它可以在DOS控制台和msysgit中工作。

根据VonC的建议,这对我很有效(差点把我逼疯了):

git config --global core.editor "'C:/Program Files (x86)/Sublime Text 3/subl.exe' -wait"

省略-wait可能会导致问题,特别是如果你正在使用Gerrit,并且更改id必须手动复制到提交消息的底部。

我使用GIT_EDITOR变量和notepad2作为编辑器解决了类似的问题。

解决方法一:将环境变量GIT_EDITOR设置为“C:/tools/notepad2.exe”。这工作得很好,但是如果提交消息有非ascii字符,git会报错。

方案二:将“GIT_EDITOR”设置为“C:/tools/notepad2.exe //utf8”。注意程序开关前的双斜杠。顺便说一句:-utf8也可以。

我的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工具中遇到问题,可以尝试一下。