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
I had PortableGit 1.6 working fine, but after upgrading to the PortableGit 1.7 Windows release, I had problems. Some of the Git commands opens up the Notepad++.exe fine, but some don't, especially Git rebase behaves differently.
The problem is some commands run the Windows cmd process and some use the Unix cmd process. I want to give startup attributes to Notepad++ editor, so I need to have a customized script. My solution is this.
Create a script to run an appropriate text editor. The script looks weird, but it handles both the 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 %*
Set the global core.editor variable
The script was saved to git/cmd folder, so it's already in a gitconsole path. This is mandatory as a full path may not work properly.
git config --global core.editor "git-editor.bat"
Now I can run the git commit -a and git rebase -i master commands. Give it a try if you have problems in the Git Windows tool.
I right clicked the Atom icon at the desktop and clicked on properties.
Copied the "Start in" location path
Looked over there with Windows Explorer and found "atom.exe".
I typed this in Git Bash:
git config --global core.editor C:/Users/YOURNAMEUSER/AppData/Local/atom/app-1.7.4/atom.exe"
Note: I changed all \
for /
. I created a .bashrc at my home directory and used /
to set my home directory and it worked, so I assumed /
will be the way to go.
atom-editor git git-bash windows-10
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.
Configuringgit 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).
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)
launch_editor()
: indicate that Git waits for user inputWhen a graphical
GIT_EDITOR
is spawned by a Git command that opens and waits for user input (e.g. "git rebase -i
"), then the editor window might be obscured by other windows.
The user might be left staring at the original Git terminal window without even realizing that s/he needs to interact with another window before Git can proceed. To this user Git appears hanging.Print a message that Git is waiting for editor input in the original terminal and get rid of it when the editor returns, if the terminal supports erasing the last line
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. Note the direction of the slashes! Use /
NOT \
to separate folders in the path name!
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:
lightfire228 adds in the comments:
For anyone having an issue where N++ just opens a blank file, and git doesn't take your commit message, see "Aborting commit due to empty message": change your
.bat
or.sh
file to say:
"<path-to-n++" .git/COMMIT_EDITMSG -<arguments>.
That will tell notepad++ to open the temp commit file, rather than a blank new one.
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 environment variable 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
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 repository in a Git shell I just set the following:
git config --global core.editor vim
which works great.