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:32

I've had difficulty getting git to cooperate with wordpad, KomodoEdit and pretty much every other editor I give it. Most open for editing, but git clearly doesn't wait for the save/close to happen.

As a crutch, I've just been doing i.e.

git commit -m "Fixed the LoadAll method"

to keep things moving. Tends to keep my commit messages a little shorter than they probably should be, but clearly there's some work to be done on the Windows version of git.

The GitGUI also isn't that bad. It takes a little bit of orientation, but after that, it works fairly well.

查看更多
听够珍惜
3楼-- · 2018-12-31 16:33

I had PortableGit 1.6 working fine but after upgrading to PortableGit-1.7 windows release had problems. Some of the git commands opens up Notepad++.exe fine but some don't, especially git rebase behaves differently.

Problem is some commands run windows cmd process some use unix cmd process. I want to give startup attributes to Notepad++ editor so need to have a customized script. My solution is this.

1) Create a script to run an appropriate text editor. Script looks weird but handles both windows and unix variation. c:/PortableGit/cmd/git-editor.bat

#!/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 %*

2) Set global core.editor variable Script was saved to git/cmd folder so its already in a gitconsole path, this is mandatory as full path may not work properly.

git config --global core.editor "git-editor.bat"

Now I can run git commit -a and git rebase -i master commands. Give it a try if you have problems in Git windows tool.

查看更多
回忆,回不去的记忆
4楼-- · 2018-12-31 16:33

I've just had the same problem and found a different solution. I was getting

error: There was a problem with the editor 'ec'

I've got VISUAL=ec, and a batch file called ec.bat on my path that contains one line:

c:\emacs\emacs-23.1\bin\emacsclient.exe %*

This lets me edit files from the command line with ec <filename>, and having visual set means most unixy programs pick it up too. Git seems to search the path differently to my other commands though - when I looked at a git commit in ProcMon I saw it look in every folder on the path for ec and for ec.exe, but not for ec.bat. I added another environment variable (GIT_EDITOR=ec.bat) and all was fine.

查看更多
大哥的爱人
5楼-- · 2018-12-31 16:33

I needed to do both of the following to get git to launch notepad++ in windoze:

-add the following to .gitconfig:

editor = 'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin

-modify the shortcut to launch the git bash shell to run as administrator, and then use that to launch the git bash shell. I was guessing that the context menu entry "Git Bash here" was not launching npp with the required permissions.

After doing both of the above it worked.

查看更多
无色无味的生活
6楼-- · 2018-12-31 16:33

Here is a solution with Cygwin:

#!/bin/dash -e
if [ "$1" ]
then k=$(cygpath -w "$1")
elif [ "$#" != 0 ]
then k=
fi
Notepad2 ${k+"$k"}
  1. If no path, pass no path

  2. If path is empty, pass empty path

  3. If path is not empty, convert to Windows format.

Then I set these variables:

export EDITOR=notepad2.sh
export GIT_EDITOR='dash /usr/local/bin/notepad2.sh'
  1. EDITOR allows script to work with Git

  2. GIT_EDITOR allows script to work with Hub commands

Source

查看更多
十年一品温如言
7楼-- · 2018-12-31 16:34

Wordpad!

I'm happy using vim, but since I'm trying to introduce Git to the company I wanted something that we'd all have, and found that Wordpad seems to work okay (i.e. Git does wait until you're finished editing and close the window).

git config core.editor '"C:\Program Files\Windows NT\Accessories\wordpad.exe"'

That's using Git Bash on msysgit; I've not tried from the Windows command prompt (if that makes any difference).

查看更多
登录 后发表回答