更新2010 - 2011:
Zumalifeguard的解决方案比原来的更简单,因为它不再需要外壳包装器脚本。
正如我在“如何在Windows上设置一个编辑器来使用Git ?”一文中所解释的那样,我更喜欢包装器,因为它更容易尝试和切换编辑器,或更改一个编辑器的路径,而不必再次用Git配置注册所做的更改。
但那只是我。
附加信息:以下解决方案适用于Cygwin,而zuamlifeguard的解决方案不适用。
最初的回答。
以下几点:
C:\prog\git>git config --global core.editor C:/prog/git/npp.sh
C:/prog/git/npp.sh:
#!/bin/sh
"c:/Program Files/Notepad++/notepad++.exe" -multiInst "$*"
做的工作。这些命令被解释为shell脚本,因此有了将任何windows命令集包装在sh脚本中的想法。
(正如Franky评论的那样:“记得用Unix风格的行尾保存你的.sh文件,否则会收到神秘的错误消息!”)
关于SO问题的更多细节,我如何在Windows上设置一个编辑器来使用Git ?
注意'-multiInst'选项,确保Git的每次调用都有一个新的notepad++实例。
还要注意的是,如果你在Cygwin上使用Git(并且想从Cygwin中使用notepad++),那么scphantm在“在Cygwin中使用notepad++ for Git”中解释说,你必须意识到:
Git正在向它传递cygwin路径,NPP不知道该如何处理它
所以在这种情况下的脚本将是:
#!/bin/sh
"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$(cygpath -w "$*")"
多行提高可读性:
#!/bin/sh
"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -notabbar \
-nosession -noPlugin "$(cygpath -w "$*")"
其中"$(cygpath -w "$*")"是这里的重要部分。
Val评论(然后删除),你不应该使用-notabbar选项:
在rebase期间禁用标签没有什么好处,但对一般记事本的可用性造成了很大的伤害,因为-notab成为默认设置,你必须设置>Preferences> general >TabBar> Hide>uncheck每次你在rebase后启动记事本。这是地狱。你推荐了地狱。
所以用rather:
#!/bin/sh
"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -nosession -noPlugin "$(cygpath -w "$*")"
那就是:
#!/bin/sh
"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -nosession \
-noPlugin "$(cygpath -w "$*")"
如果你想把脚本'npp.sh'放在一个有空格的路径中(如
` c:\program files\…`,),你有三个选项:
Either try to quote the path (single or double quotes), as in:
git config --global core.editor 'C:/program files/git/npp.sh'
or try the shortname notation (not fool-proofed):
git config --global core.editor C:/progra~1/git/npp.sh
or (my favorite) place 'npp.sh' in a directory part of your %PATH% environment variable. You would not have then to specify any path for the script.
git config --global core.editor npp.sh
Steiny reports in the comments having to do:
git config --global core.editor '"C:/Program Files (x86)/Git/scripts/npp.sh"'