How can I set up an editor to work with Git on Win

2018-12-31 16:21发布

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?

30条回答
倾城一夜雪
2楼-- · 2018-12-31 16:44

Vim/Gvim works well for me.

>echo %EDITOR%

c:\Vim\Vim71\vim.exe
查看更多
路过你的时光
3楼-- · 2018-12-31 16:46

This is my setup to use Geany as an editor for git:

git config --global core.editor C:/path/to/geany.bat

with the following content in geany.bat :

#!/bin/sh
"C:\Program Files\Geany\bin\Geany.exe" --new-instance "$*"

It works in both DOS console and msysgit.

查看更多
余欢
4楼-- · 2018-12-31 16:48

Edit .gitconfig file in c:\Users\YourUser folder and add:

[core]
editor = 'C:\\Program files\\path\\to\\editor.exe'
查看更多
梦该遗忘
5楼-- · 2018-12-31 16:49

Resurrecting an old thread, but I found a a beautifully simple solution posted here - although there may be a mistake in the path in which you have to copy over the "subl" file given by the author. I am running Win 7 x64 and I had to put the "subl" file in my /Git/cmd/ folder to make it work. It works like a charm though.

查看更多
宁负流年不负卿
6楼-- · 2018-12-31 16:51

I also use Cygwin on Windows, but with gvim (as opposed to the terminal-based vim).

To make this work, I have done the following:

  1. Created a one-line batch file (named git_editor.bat) which contains the following:
    "C:/Program Files/Vim/vim72/gvim.exe" --nofork "%*"
  2. Placed git_editor.bat on in my PATH.
  3. Set GIT_EDITOR=git_editor.bat

With this done, git commit, etc. will correctly invoke the gvim executable.

NOTE 1: The --nofork option to gvim insures that it blocks until the commit message has been written.

NOTE 2: The quotes around the path to gvim is required if you have spaces in the path.

NOTE 3: The quotes around "%*" are needed just in case git passes a file path with spaces.

查看更多
冷夜・残月
7楼-- · 2018-12-31 16:52

I managed to get the environment version working by setting the EDITOR variable using quotes and /:

EDITOR="c:/Program Files (x86)/Notepad++/notepad++.exe"
查看更多
登录 后发表回答