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

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

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

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

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


当前回答

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

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

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

其他回答

这是为我使用Cygwin和TextPad 6工作(编辑:它也与TextPad 5工作,只要你对脚本做出明显的改变),想必模型也可以用于其他编辑器:

文件~ / .gitconfig:

[core]
    editor = ~/script/textpad.sh

文件~ /脚本/ textpad.sh:

#!/bin/bash

APP_PATH=`cygpath "c:/program files (x86)/textpad 6/textpad.exe"`
FILE_PATH=`cygpath -w $1`

"$APP_PATH" -m "$FILE_PATH"

这一行代码也同样有效:

文件~/script/textpad.sh(选项2):

"`cygpath "c:/program files (x86)/textpad 6/textpad.exe"`" -m "`cygpath -w $1`"

对于Atom,你可以这样做

git config --global core.editor "atom --wait"

Visual Studio Code也类似

git config --global core.editor "code --wait"

它会打开一个Atom或Visual Studio Code窗口供你提交,

或Sublime Text:

git config --global core.editor "subl -n -w"

我的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与写字板、科莫多编辑器以及我给它的几乎所有其他编辑器合作。大多数打开以供编辑,但Git显然不会等待保存/关闭发生。

作为拐杖,我一直在做。

git commit -m "Fixed the LoadAll method"

让事情继续发展。它往往会使我的提交消息比应该的要短一些,但显然在Windows版本的Git上还有一些工作要做。

GitGUI也不是那么糟糕。它需要一点定位,但在那之后,它工作得很好。

当使用远程挂载的主驱动器(Samba共享、NFS,…)时,您的~/。Git文件夹在所有系统中共享,这可能会导致几个问题。因此,我更喜欢用脚本来确定正确系统的正确编辑器:

#!/usr/bin/perl
# Detect which system I'm on and choose the right editor
$unamea = `uname -a`;
if($unamea =~ /mingw/i){
    if($unamea =~ /devsystem/i){#Check hostname
        exec('C:\Program Files (x86)\Notepad++\notepad++.exe', '-multiInst', '-nosession', @ARGV);
    }
    if($unamea =~ /testsystem/i){
        exec('C:\Program Files\Notepad++\notepad++.exe', '-multiInst', '-nosession', @ARGV);
    }
}
$MCEDIT=`which mcedit`;
if($MCEDIT =~ /mcedit/){
    exec($MCEDIT, @ARGV);
}
$NANO=`which nano`;
if($NANO =~ /nano/){
    exec($NANO, @ARGV);
}
die "You don't have a suitable editor!\n";

人们可能会考虑使用普通的shell脚本,但我使用的是Perl,因为它随msysgit一起提供,而且您的类unix系统通常也会提供一个。 将脚本放在/home/username/bin中,该脚本应该添加到.bashrc或.profile中的PATH中。一旦添加了git配置-全局核心。编辑器giteditor。pl你有正确的编辑器,无论你在哪里。