views:

9573

answers:

16

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 couldn't care less what editor I use. I just want to be able to type my commit messages without using -m.

So, for those of you using Git on Windows: What (free) tool do you use to edit your commit message, and what do you get when you type echo %EDITOR% at the command prompt?

+2  A: 

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 a

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.

J Wynia
+9  A: 

Notepad++ works just fine, although I choose to stick with Notepad, -m, or even sometimes the built-in "edit."

The problem you are encountering using Notepad++ is related to how git is launching the editor executable. My solution to this is to set EDITOR to a batch file, rather than the actual editor executable, that does the following:

start /WAIT "E:\PortableApps\Notepad++Portable\Notepad++Portable.exe" %*

/WAIT tells the command line session to halt until the application exits, thus you will be able to edit to your heart's content while git happily waits for you. %* passes all arguments to the batch file through to Notepad++.

c:\src>echo %EDITOR%
c:\tools\runeditor.bat
Patrick Johnmeyer
I had trouble getting this to work under powershell. This method (http://stackoverflow.com/questions/10564/how-can-i-set-up-an-editor-to-work-with-git-on-windows/773973#773973) worked fine though.
Peter Stephens
+5  A: 

Vim/Gvim works well for me.

>echo %EDITOR%

c:\Vim\Vim71\vim.exe
Matt McMinn
+2  A: 

It seems as if Git won't find the editor if there are spaces in the path. So you will have to put the batch file mentioned in Patrick's answer into a non-whitespace path.

This format works fine for paths with spaces:git config --global core.editor "\"c:\Program Files\textpad 5\textpad.exe\""so it may be practical for you to avoid creating a batch file
Carl
+25  A: 

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

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"

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:

VonC
In your shell script, you need double quotes around $*, otherwise it won't work properly for paths with spaces in them. Thanks for the thorough explanation - I'm installing git (and a bunch of other stuff) on Windows for beginning programmers, and the command line is hard enough to grok without making them learn vi commands.
Sarah Mei
This method works fine under powershell. Thanks!
Peter Stephens
Another concrete example: http://stackoverflow.com/questions/1634161/how-do-i-use-notepad-or-other-with-msysgit/1635493#1635493
VonC
Following [Bennett's answer](http://stackoverflow.com/questions/10564/how-can-i-set-up-an-editor-to-work-with-git-on-windows/1431003#1431003) you do not need to create a script, you can just use an apostrophe ' inside the quotes ".
Tobias Kienzler
@Tobias: true, I have included his answer in mine, as well as the reason why I still prefer referencing a script in my `git config` settings.
VonC
+11  A: 

Sorry peeps, I'm new to answering on StackOverflow - getting confused over who answered this and who edited that, lol.

Anyway, I've just been playing around with this and found the following to work nicely for me:

git config --global core.editor "'C:/Program Files/TextPad 5/TextPad.exe' -m"

I don't think CMD likes single-quotes so you must use double quotes "to specify the space embedded string argument".

Cygwin (which I believe is the underlying platform for Git's Bash) on the other hand likes both ' and "; you can specify a CMD-like paths, using / instead of \, so long as the string is quoted i.e. in this instance, using single-quotes.

The -m overrides/indicates the use of multiple editors and there is no need for a %* tacked on the end.

Cheers Darren

Darren
Nice one, thanks!
IanVaughan
+1  A: 

I use Cygwin on Windows, so I use

export EDITOR="emacs -nw"

the "-nw" is for "no-windows", i.e. tell emacs not to try and use X11

The emacs keybindings don't work for me from a Windows shell, so I would only use this from a Cygwin shell... (rxvt recommended)

bjnortier
+2  A: 

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.

Tom Dunham
+14  A: 

Building on Darren's answer, to use Notepad++ you can simply do this:

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

Works like a charm for me.

Bennett McElwee
+2  A: 

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.

Tim Henigan
+1  A: 

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.

Whome
A: 

this is all fine and dandy but AFTER you get this setup IE


[core] editor = 'C:/Program Files/Notepad++/notepad++.exe'

how do you access the notepad++ ... like in the examples ive seen theres a command like

mate .gitignore

where "mate" is a established shortcut to the editing program ... in this case "TextMate"

... how do i get this to work for notepad++?

delinquentme
You can post a new question by clicking [Ask Question] at the top of the page. I don't have an answer for you, but someone who does is much more likely to notice if you post a new question.
Patrick McElhaney
A: 

I prefer to use emacs. Getting it set up can be a little tricky.

  1. Download emacs and unpack it somewhere like c:\emacs.
  2. Run c:\emacs\bin\addpm.exe. You need to right-click and "Run as Administrator" if you are using Windows Vista or above. This will put the executables in your path.
  3. Add (server-start) somewhere in your .emacs file. See the Emacs Windows FAQ for advice on where to put your .emacs file.
  4. git config --global core.editor emacsclientw

Git will now open files within an existing emacs process. You will have to run that existing process manually from c:\emacs\bin\runemacs.exe.

Michael Steele
A: 

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).

Gavin Schultz-Ohkubo
A: 

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.

CharlesB
A: 

i have a very simple question:

gedit is my default (commit) editor. in the terminal, when i type 'git commit -a', it is opened; then i type a commit message using gedit, save it, but git doesn't effectively commits!

so, when i type 'git status', it doesn't show me 'nothing to commit' message...

what should i do, in order to fix this problem?

Paulo Cassiano
Paulo, this isn't a forum. If you have a question of your own, you should ask it as a separate "question", not as an answer to someon else's question.
Will Vousden