如何设置编辑器在Windows上使用Git?

如何设置编辑器在Windows上使用Git?,windows,git,cygwin,editor,atom-editor,git-bash,windows-10,Windows,Git,Cygwin,Editor,Atom Editor,Git Bash,Windows 10,我正在Windows上试用Git。我要尝试“git提交”,但出现了以下错误: 终端是哑的,但不可见或不可见 编辑器定义。请提供 使用-m或-F选项的消息 所以我想我需要一个名为EDITOR的环境变量。没问题。我将它设置为指向记事本。这几乎奏效了。默认提交消息将在记事本中打开。但记事本不支持裸线提要。我去了,得到了,但我不知道如何将Notepad++设置为%EDITOR%,这样它就可以像预期的那样与Git一起工作 我没有嫁给记事本++。在这一点上,我不介意我使用什么编辑器。我只希望能够在编辑器中而

我正在Windows上试用Git。我要尝试“git提交”,但出现了以下错误:

终端是哑的,但不可见或不可见 编辑器定义。请提供 使用-m或-F选项的消息

所以我想我需要一个名为EDITOR的环境变量。没问题。我将它设置为指向记事本。这几乎奏效了。默认提交消息将在记事本中打开。但记事本不支持裸线提要。我去了,得到了,但我不知道如何将Notepad++设置为
%EDITOR%
,这样它就可以像预期的那样与Git一起工作

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


在Windows上使用Git的人:您使用什么工具来编辑提交消息?您必须做些什么才能使其正常工作?

我很难让Git与我提供的其他编辑器合作。大多数都是开放编辑的,但Git显然不会等待保存/关闭

作为一个拐杖,我刚刚做了I.e

git commit -m "Fixed the LoadAll method"
让事情继续发展。它倾向于使我的提交消息比它们可能应该的要短一点,但显然在Git的Windows版本上还有一些工作要做


GitGUI也没有那么糟糕。它需要一点定向,但在那之后,它工作得相当好。

记事本++工作得很好,尽管我选择使用记事本,-m,有时甚至是内置的“编辑”

使用Notepad++时遇到的问题与Git如何启动编辑器可执行文件有关。我的解决方案是将环境变量
EDITOR
设置为批处理文件,而不是实际的编辑器可执行文件,该文件执行以下操作:

start /WAIT "E:\PortableApps\Notepad++Portable\Notepad++Portable.exe" %*
git config --global core.editor vim
/WAIT
告诉命令行会话停止,直到应用程序退出,这样,当Git愉快地等待您时,您就可以编辑自己的内容了。%*将批处理文件的所有参数传递到Notepad++

C:\src> echo %EDITOR%
C:\tools\runeditor.bat
对我来说很好

>echo %EDITOR%

c:\Vim\Vim71\vim.exe

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

2015年9月更新(6年后)

目前的方案包括:

通过配置git config core.editor记事本,用户 配置
git config format.commitMessageColumns 72
将由记事本包装器拾取,并在用户编辑提交消息后将其换行

再见

Git 2.16(2018年第1季度)将显示一条消息,告知用户在生成编辑器时正在等待用户完成编辑,以防编辑器 打开到一个隐藏的窗口或某个模糊的地方,用户可以 迷路了

参见(2017年12月7日)和(2017年11月29日)作者。
帮助人:。
(于2017年12月19日被合并)

启动编辑器()
:指示Git等待用户输入 当打开的GIT命令生成图形
GIT\u编辑器时
并等待用户输入(例如“
git-rebase-i
”),然后打开编辑器窗口 可能会被其他窗口遮挡。
用户可能会一直盯着屏幕 原来的Git终端窗口甚至没有意识到他/她需要 在Git继续之前与另一个窗口交互。向该用户发送Git 看起来像是挂着的

打印Git正在等待编辑器输入的消息 当编辑器返回时,如果终端 支持擦除最后一行


原始答案

我刚刚用git版本1.6.2.msysgit.0.186.gf7512和Notepad++5.3.1测试了它

我不希望设置编辑器变量,因此我尝试:

git config--global core.editor“\”c:\Program Files\Notepad++\Notepad++.exe“
#或
git config--global core.editor“\”c:\Program Files\Notepad++\Notepad++.exe \“%*”
这通常会带来:

C:\prog\git>git config --global --edit
"c:\Program Files\Notepad++\notepad++.exe" %*: c:\Program Files\Notepad++\notepad++.exe: command not found
error: There was a problem with the editor '"c:\Program Files\Notepad++\notepad++.exe" %*'.
如果我定义npp.bat,包括:

"c:\Program Files\Notepad++\notepad++.exe" %*
我输入:

C:\prog\git>git config --global core.editor C:\prog\git\npp.bat
它只在DOS会话中工作,但不在git shell中工作
(不是说在core.editor配置机制中,包含“
start/WAIT…
”的脚本无法工作,而是只能打开一个新的DOS窗口)


提到避免添加脚本的可能性,但在简单引号之间直接引用程序本身。注意斜线的方向!使用
/
而不是
\
来分隔路径名中的文件夹

git config--global core.editor\ “'C:/Program Files/Notepad++/Notepad++.exe'-multiInst-notabbar-nosession-noPlugin”
或者,如果您在64位系统中:

git config--global core.editor\ “'C:/ProgramFiles(x86)/Notepad++/Notepad++.exe'-multiInst-notabbar-nosession-noPlugin” 但我更喜欢使用脚本(见下文):这样我就可以使用不同的路径或不同的选项,而无需再次注册
git config


实际的解决方案(使用脚本)是认识到:
您在配置文件中所指的实际上是一个shell(
/bin/sh
)脚本,而不是DOS脚本

那么,工作原理是:

C:\prog\git>git config --global core.editor C:/prog/git/npp.bat
使用
C:/prog/git/npp.bat

#!/bin/sh
"C:\Program Files\Geany\bin\Geany.exe" --new-instance "$*"
#/垃圾箱/垃圾箱
“c:/Program Files/Notepad++/Notepad++.exe”-multiInst“$*”

#/垃圾箱/垃圾箱
“c:/Program Files/Notepad++/Notepad++.exe”-multiInst-notabbar-nosession-noPlugin”$*”
通过该设置,我可以从DOS或git Shell执行“
git config--global--edit
”,也可以从DOS或git Shell执行“
git rebase-I…”
”。
Bot命令将触发记事本++的新实例(因此有
-multiInst
”选项),并等待该实例关闭后再继续

N
export EDITOR="emacs -nw"
error: There was a problem with the editor 'ec'
c:\emacs\emacs-23.1\bin\emacsclient.exe %*
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
#!/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 %*
git config --global core.editor "git-editor.bat"
git config core.editor '"C:\Program Files\Windows NT\Accessories\wordpad.exe"'
git config --global core.editor C:/path/to/geany.bat
#!/bin/sh
"C:\Program Files\Geany\bin\Geany.exe" --new-instance "$*"
git config --global core.editor "gvim --nofork '%*'"
EDITOR="c:/Program Files (x86)/Notepad++/notepad++.exe"
export TERM=msys
echo "export TERM=msys" >> ~/.bashrc
git config --global core.editor c:/msysgit/cmd/epp.sh
#!/bin/sh
"C:/Program Files/JGsoft/EditPadPro6/EditPadPro.exe" //newinstance "$*"
[core]
    editor = ~/script/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"
"`cygpath "c:/program files (x86)/textpad 6/textpad.exe"`" -m "`cygpath -w $1`"
git config --global core.editor giteditor
git config --global core.editor vim
[core]
    editor = 'c:/program files/sublime text 3/subl.exe' -w
git config --global core.editor "'C:/Program Files (x86)/Sublime Text 3/subl.exe' -wait"
git config --global core.editor C:/Users/YOURNAMEUSER/AppData/Local/atom/app-1.7.4/atom.exe"
git config --global core.editor "atom --wait"
git config --global core.editor "code --wait"
git config --global core.editor "subl -n -w"
[core]
editor = 'C:\\Program files\\path\\to\\editor.exe'
editor = 'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin