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

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.

查看更多
明月照影归
3楼-- · 2018-12-31 16:28

ATOM and Windows 10

  1. Right clicked the Atom icon at the desktop and clicked on properties.
  2. Copied the "Start in" location path
  3. Looked over there with the windows explorer and found "atom.exe".
  4. Typed this in the 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.

查看更多
梦该遗忘
4楼-- · 2018-12-31 16:29

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

查看更多
查无此人
5楼-- · 2018-12-31 16:29

When using a remotely mounted homedrive (samba share, nfs, ...) your ~/.git folder is shared acros all systems which can lead to several problems. Thus I prefer a script to determine the right editor for the right system:

#!/usr/bin/perl
# Detect which system I'm on and choose the right editor
$unamea = `uname -a`;
if($unamea =~ /mingw/i){
    if($unamea =~ /devsystem/i){#Check hostname
        exec('C:\Program Files (x86)\Notepad++\notepad++.exe', '-multiInst', '-nosession', @ARGV);
    }
    if($unamea =~ /testsystem/i){
        exec('C:\Program Files\Notepad++\notepad++.exe', '-multiInst', '-nosession', @ARGV);
    }
}
$MCEDIT=`which mcedit`;
if($MCEDIT =~ /mcedit/){
    exec($MCEDIT, @ARGV);
}
$NANO=`which nano`;
if($NANO =~ /nano/){
    exec($NANO, @ARGV);
}
die "You don't have a suitable editor!\n";

One might consider a plain shell script but I used perl as is perl is shipped with msysgit und your unixoid systems will provide one as well. Putting the script in /home/username/bin, which should be added to PATH in .bashrc or .profile. Once added with git config --global core.editor giteditor.pl you have the right editor, wherever you are.

查看更多
深知你不懂我心
6楼-- · 2018-12-31 16:31

This is the 1 symptom of greater issues. Notably that you have something setting TERM=dumb. Other things that don't work properly are the less command which says you don't have a fully functional terminal. It seems like this is most commonly caused by having TERM set to something in your global windows environment variables. For me, the issue came up when I installed Strawberry Perl some info about this is on the msysgit bug for this problem as well as several solutions.

The first solution is to fix it in your ~/.bashrc by adding:

export TERM=msys

You can do this from the Git BASH prompt like so:

echo "export TERM=msys" >> ~/.bashrc

The other solution which ultimately is what I did because I don't care about Strawberry Perl's reasons for adding TERM=dumb to my environment settings is to go and remove the TERM=dumb as directed in this comment on the msysgit bug report.

Control Panel/System/Advanced/Environment Variables... (or similar, depending on your version of Windows) is where sticky environment variables are set on Windows. By default, TERM is not set. If TERM is set in there, then you (or one of the programs you have installed - eg. Strawberry Perl) has set it. Delete that setting, and you should be fine.

Similarly if you use Strawberry Perl and care about the CPAN client or something like that, you can leave the TERM=dumb alone and use unset TERM in your ~/.bashrc file which will have a similar effect to setting an explicit term as above.

Of course all the other solutions are correct that you can use git config --global core.editor $MYFAVORITEEDITOR to make sure that git uses your favorite editor when it needs to launch one for you.

查看更多
深知你不懂我心
7楼-- · 2018-12-31 16:32

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.

查看更多
登录 后发表回答