如何设置一个编辑器在Windows上使用Git? [英] How can I set up an editor to work with Git on Windows?

查看:1337
本文介绍了如何设置一个编辑器在Windows上使用Git?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


终端是哑的,但没有VISUAL和
EDITOR定义。请使用-m或-F选项提供
消息。


所以我想我需要一个环境变量叫EDITOR。没问题。我设置它指向记事本。这工作,差不多。默认提交消息在记事本中打开。但记事本不支持裸行Feed。我出去了,并获得了记事本++ ,但我不知道如何获得Notepad ++设置为%EDITOR%,这样它就像Git一样工作。



m没有结婚到记事本++。在这一点上我不介意我使用的是什么编辑器。我只想在编辑器中输入提交讯息,而不是命令行( -m )。



你在Windows上使用Git:你使用什么工具来编辑提交信息,以及你需要做什么来使它工作?

解决方案

2015年9月更新(6年后)



的最新版本现在包括:


通过配置 git config core.editor notepad 现在可以使用 notepad.exe 作为其默认编辑器

配置 git config format.commitMessageColumns 72 将由记事本包装器接收并换行提交


请参阅 commit 69b301b by Johannes Schindelin( dscho






原始回答

b

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



我喜欢 必须设置一个EDITOR变量,所以我试过:

  git config --global core.editor\c:\Program Files \Notepad ++ \\\
otepad ++。exe \
#或
git config --global core.editor\ c:\Program Files\ Notepad ++ \\\
otepad ++。exe \%*

这总是:

  C:\prog\git> git config --global --edit 
c:\Program Files \Notepad ++ \\\
otepad ++。exe%*:c:\Program Files \Notepad ++ \\\
otepad ++。exe:command not found
错误: c:\Program Files \Notepad ++ \\\
otepad ++。exe%*'。

如果我定义了一个npp.bat,包括:

 c:\Program Files\ Notepad ++ \\\
otepad ++。exe%*

和我键入:

  C:\prog\git> git config  - global core.editor C:\prog\git\\\
pp.bat

DOS会话但不是从git shell

(不是使用core.editor配置机制,脚本使用 start / WAIT。 .. 无效,但只打开一个新的DOS窗口)






Bennett的回答提到了避免添加脚本,而直接引用程序本身之间的简单引号的可能性:

  git config --global core.editor \ 
'C:/ Program Files / Notepad ++ / notepad ++。exe'-multiInst -notabbar -nosession -noPlugin

或者如果您使用的是64位系统:



但我更喜欢使用一个脚本我可以使用不同的路径或不同的选项,而不必再次注册 git config






实际的解决方案(使用脚本)是要实现:

你在配置文件中引用的实际上是一个shell( / bin / sh ,而不是DOS脚本。




$ b

  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$ *


$ b b:\\ Program Files \\ Notepad ++ / notepad ++。exe-multiInst -notabbar -nosession - > / noPlugin$ *



使用该设置,我可以做' git config --global --edit '从DOS或Git Shell,或者我可以从DOS或Git做' git rebase -i ... Shell。

Bot命令将触发一个新的notepad ++实例(因此是 -multiInst '选项),并等待该实例关闭



请注意,我只使用/,而不是 \ '。并且我使用选项2安装了msysgit。(将 git\bin 目录添加到 PATH 环境变量,但不覆盖某些内置窗口工具)



notepad ++ wrapper被称为.bat的事实并不重要。

最好命名为npp.sh并将其放在 [git] \cmd 目录中(或在您的PATH环境变量引用的任何目录中)。






另请参阅:




I'm trying out Git on Windows. I got to the point of trying "git commit" and I got this error:

Terminal is dumb but no VISUAL nor EDITOR defined. Please supply the message using either -m or -F option.

So I figured out I need to have an environment variable called EDITOR. No problem. I set it to point to Notepad. That worked, almost. The default commit message opens in Notepad. But Notepad doesn't support bare line feeds. I went out and got Notepad++, but I can't figure out how to get Notepad++ set up as the %EDITOR% in such a way that it works with Git as expected.

I'm not married to Notepad++. At this point I don't mind what editor I use. I just want to be able to type commit messages in an editor rather than the command line (with -m).

Those of you using Git on Windows: What tool do you use to edit your commit messages, and what did you have to do to make it work?

解决方案

Update September 2015 (6 years later)

The last release of git-for-Windows (2.5.3) now includes:

By configuring git config core.editor notepad, users can now use notepad.exe as their default editor.
Configuring git config format.commitMessageColumns 72 will be picked up by the notepad wrapper and line-wrap the commit message after the user edits it.

See commit 69b301b by Johannes Schindelin (dscho).


Original answer

I just tested it with git version 1.6.2.msysgit.0.186.gf7512 and Notepad++5.3.1

I prefer to not have to set an EDITOR variable, so I tried:

git config --global core.editor "\"c:\Program Files\Notepad++\notepad++.exe\""
# or
git config --global core.editor "\"c:\Program Files\Notepad++\notepad++.exe\" %*"

That always gives:

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" %*'.

If I define a npp.bat including:

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

and I type:

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

It just works from the DOS session, but not from the git shell.
(not that with the core.editor configuration mechanism, a script with "start /WAIT..." in it would not work, but only open a new DOS window)


Bennett's answer mentions the possibility to avoid adding a script, but to reference directly the program itself between simple quotes:

git config --global core.editor \
"'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

Or if you are in a 64 bit system:

git config --global core.editor \
"'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

But I prefer using a script (see below): that way I can play with different paths or different options without having to register again a git config.


The actual solution (with a script) was to realize that:
what you refer to in the config file is actually a shell (/bin/sh) script, not a DOS script.

So what does work is:

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

with C:/prog/git/npp.bat:

#!/bin/sh
"c:/Program Files/Notepad++/notepad++.exe" -multiInst "$*"

or

#!/bin/sh
"c:/Program Files/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$*"

With that setting, I can do 'git config --global --edit' from DOS or Git Shell, or I can do 'git rebase -i ...' from DOS or Git Shell.
Bot commands will trigger a new instance of notepad++ (hence the -multiInst' option), and wait for that instance to be closed before going on.

Note that I use only '/', not \'. And I installed msysgit using option 2. (Add the git\bin directory to the PATH environment variable, but without overriding some built-in windows tools)

The fact that the notepad++ wrapper is called .bat is not important.
It would be better to name it 'npp.sh' and to put it in the [git]\cmd directory though (or in any directory referenced by your PATH environment variable).


See also:

这篇关于如何设置一个编辑器在Windows上使用Git?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆