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?
Thanks to the SO community ... and a little research I was able to get my favorite editor, EditPadPro, to work as the core editor with msysgit 1.7.5.GIT and TortoiseGit v1.7.3.0 over WinXP SP3 ...
Following the advice above I added the path to a bash script for the code editor ...
However after several failed attempts at the above mentioned solutions ... I was finally able to get this working. Per EditPadPro's documentation, adding the '/newinstance' flag would allow the shell to wait for the editor input ....
The '/newinstance' flag was the key in my case ...
Update September 2015 (6 years later)
The last release of git-for-Windows (2.5.3) now includes:
See commit 69b301b by Johannes Schindelin (
dscho
).And Git 2.16 (Q1 2018) will show a message to tell the user that it is waiting for the user to finish editing when spawning an editor, in case the editor opens to a hidden window or somewhere obscure and the user gets lost.
See commit abfb04d (07 Dec 2017), and commit a64f213 (29 Nov 2017) by Lars Schneider (
larsxschneider
).Helped-by: Junio C Hamano (
gitster
).(Merged by Junio C Hamano --
gitster
-- in commit 0c69a13, 19 Dec 2017)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:
That always gives:
If I define a npp.bat including:
and I type:
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. Note the direction of the slashes! Use
/
NOT\
to separate folders in the path name!Or if you are in a 64 bit system:
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:
with
C:/prog/git/npp.bat
:or
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 thegit\bin
directory to thePATH
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:
lightfire228 adds in the comments:
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.
I'm using GitHub for Windows which is a nice visual option. But I also prefer the command line, so to make it work when I open a repo in a Git shell I just set the following:
which works great.
I use git on multiple platforms, and I like to use the same git settings on all of them. (In fact, I have all my configuration files under release control with git, and put a git repository clone on each machine.) The solution I came up with is this:
I set my editor to giteditor
Then I create a symbolic link called giteditor which is in my PATH. (I have a personal bin directory, but anywhere in the PATH works.) That link point to my current editor of choice. On different machines and different platforms, I use different editors, so this means that I don't have to change my universal git configuration (.gitconfig), just the link that giteditor points to.
Symbolic links are handled by every operating system I know of, though they may use different commands. For Linux, you use ln -s. For Windows, you use the cmd built-in mklink. They have different syntaxes (which you should look up), but it all works the same way, really.
For Atom you can do
and similar for VSCode
which will open up an Atom or VSCode window for you to commit through,
or for Sublime