2015 年 9 月更新(6 年后)
last release of git-for-Windows (2.5.3) 现在包括:
通过配置git config core.editor notepad,用户can now use notepad.exe as their default editor。
配置git config format.commitMessageColumns 72 将被记事本包装器拾取,并在用户编辑提交消息后对其进行换行。
见commit 69b301bJohannes Schindelin (dscho)。
并且 Git 2.16(2018 年第一季度)将显示一条消息,告诉用户它在生成编辑器时正在等待用户完成编辑,以防编辑器
打开一个隐藏的窗口或某个不明显的地方,用户得到
丢了。
请参阅commit abfb04d(2017 年 12 月 7 日)和Lars Schneider (larsxschneider)commit a64f213(2017 年 11 月 29 日)。
帮助者:Junio C Hamano (gitster)。
(由 Junio C Hamano -- gitster -- 合并于 commit 0c69a13,2017 年 12 月 19 日)
launch_editor():表示Git等待用户输入
当图形 GIT_EDITOR 由打开的 Git 命令生成时
并等待用户输入(例如“git rebase -i”),然后是编辑器窗口
可能会被其他窗口遮挡。
用户可能会盯着
原来的 Git 终端窗口,甚至没有意识到他/她需要
在 Git 可以继续之前与另一个窗口进行交互。给这个用户 Git
似乎挂起。
在原文中打印一条 Git 正在等待编辑器输入的消息
终端并在编辑器返回时摆脱它,如果终端
支持擦除最后一行
原答案
我刚刚用 git 版本 1.6.2.msysgit.0.186.gf7512 和 Notepad++5.3.1 测试过
我更喜欢不必须设置一个EDITOR变量,所以我尝试了:
git config --global core.editor "\"c:\Program Files\Notepad++\notepad++.exe\""
# or
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窗口)
Bennett's answer 提到了避免添加脚本的可能性,而是直接引用程序本身在单引号之间。注意斜线的方向!使用/而不是\来分隔路径名中的文件夹!
git config --global core.editor \
"'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
或者,如果您使用的是 64 位系统:
git config --global core.editor \
"'C:/Program Files (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/Notepad++/notepad++.exe" -multiInst "$*"
或
#!/bin/sh
"c:/Program Files/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$*"
使用该设置,我可以从 DOS 或 Git Shell 执行“git config --global --edit”,或者我可以从 DOS 或 Git Shell 执行“git rebase -i ...”。
Bot 命令将触发一个新的 notepad++ 实例(因此有 -multiInst' 选项),并等待该实例关闭后再继续。
请注意,我只使用'/',而不是\'。而我installed msysgit using option 2.(将git\bin 目录添加到PATH 环境变量中,但不覆盖一些内置的windows 工具)
notepad++ 包装器被称为 .bat 的事实并不重要。
最好将其命名为“npp.sh”并将其放在[git]\cmd 目录中(或在您的 PATH 环境变量引用的任何目录中)。
另见:
lightfire228 添加in the comments:
对于遇到 N++ 只打开一个空白文件而 git 不接受您的提交消息的问题的任何人,请参阅“Aborting commit due to empty message”:将您的 .bat 或 .sh 文件更改为:
"<path-to-n++" .git/COMMIT_EDITMSG -<arguments>.
这将告诉 notepad++ 打开临时提交文件,而不是一个空白的新文件。