Git difftool not launching external DiffMerge program - windows

I've been following the directions in the "blog entry by Dave" link in this answer as I'm on Windows 7 and do use SourceGear's DiffMerge tool. I've added the git\cmd directory to my PATH system variable and put my git-diff-diffmerge-wrapper.sh file in there:
#!/bin/sh
"C:\Program Files\SourceGear\Common\DiffMerge\sgdm.exe" "$1" "$2" | cat
(Yes, it's the correct path for DiffMerge.)
I've edited my .gitconfig file to include the diff and difftool chunks (I copied the lines directly from the post, and he does leave in the commented-out #external line. I added this to the end of my file; is that OK? )
[diff]
# external = git-diff-wrapper.sh
tool = diffmerge
[difftool "diffmerge"]
cmd = git-diff-diffmerge-wrapper.sh "$LOCAL" "$REMOTE"
So I go to git bash and do git difftool HEAD~ 67b8679 -- js/site/pizzabuilder.js and hit enter. Nothing happens. If I do git difftool HEAD~ 67b8679, leaving off the file I want, I get this:
Viewing: 'js/angular/hutlovers/hutlovers.js'
Launch 'diffmerge' [Y/n]: Y
C:\Program Files (x86)\Git/libexec/git-core/mergetools/defaults: line 17: git-diff-diffmerge-wrapper.sh: command not found
Viewing: 'js/angular/localization/StoreListCtrl.js'
Launch 'diffmerge' [Y/n]: n
Viewing: 'js/pizzahut/site/browser_version.js'
Launch 'diffmerge' [Y/n]: n
Viewing: 'js/pizzahut/site/dashboard.js'
Launch 'diffmerge' [Y/n]: n
It continues for all of the files that are different between the commits, but it never launches DiffMerge. I don't know how to interpret the error; what command is not found? difftool? I'm running 1.7.11 in git, and difftool is supposedly included with git starting with version 1.6.3.
When I look at line 17 of the file referenced in the error, this is what's there:
( eval $merge_tool_cmd )
as part of this block:
diff_cmd () {
merge_tool_cmd="$(get_merge_tool_cmd "$1")"
if test -z "$merge_tool_cmd"
then
status=1
break
fi
( eval $merge_tool_cmd )
status=$?
return $status
}
Can anyone help me out? I'm a daily user of git, but hardly a power user, and I know nothing about Windows shell scripts, so following the directions in that post is pretty much the limits of my knowledge at this point.

I know this is an old question and I recognize that my situation may just be me being dumb, but I did spin my wheels trying to figure this out. Hopefully though, someone who made the same mistake as me won't be completely lost in future.
Make sure items show with git diff!
I had a very simple one line change. Did a git add . and then got interrupted. Came back to finish up and decided to double check the diffs. I did not realize that doing a git add would stop me from being able to use git difftool.
Doing a git reset allowed git difftool to work.

DiffMerge
Not sure if this well help, but this is my configuration for difftool with DiffMerge. Note that I'm using msysgit Bash (not sure if it will be different for Cygwin or PoshGit users):
[diff]
tool = dm
[difftool "dm"]
cmd = C:/Program\\ Files/SourceGear/Common/DiffMerge/sgdm.exe \"$LOCAL\" \"$REMOTE\"
I'm currently using Git 2.0, but I seem to recall having set this up with either Git 1.8.x or maybe even as early as Git 1.7.x, so try it out and see if it works.
Bonus with Beyond Compare 3 Pro
I actually do most of my diffing on Windows nowadays with Beyond Compare 3 Pro, though sometimes I will still use DiffMerge. Here are all of my difftool settings if you want to make the switch:
[merge]
tool = bc3
[diff]
tool = bc3
[difftool "dm"]
cmd = C:/Program\\ Files/SourceGear/Common/DiffMerge/sgdm.exe \"$LOCAL\" \"$REMOTE\"
[difftool "bc3"]
cmd = "\"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\""
[mergetool "bc3"]
cmd = "\"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\""

None of the other answers worked for me. I finally got diffmerge to work on Windows 7,8,10 using Git 2.6.3, 2.7.0
1) Make sure you can write to and use your global .gitconfig stored at ~/.gitconfig, which is relative to your HOME path.
Use:
git config --global --edit
or just navigate to the file in a windows explorer and edit it that way.
The HOME variable can be set by navigating to environment variables within windows (for 7, right click on Computer-->Properties-->Advanced system settings-->Environment Variables).
2) Make sure diffmerge is in your PATH variable on your machine. This is in the same place as the HOME variable.
I added this to my PATH:
C:\Program Files\SourceGear\Common\DiffMerge;
3) To make diffmerge the default add the following to your global .gitconfig file:
[merge]
tool = diffmerge
[mergetool]
prompt = true
[mergetool "diffmerge"]
path = C:\\Program Files\\SourceGear\\Common\\DiffMerge\\sgdm.exe
'\' is an escape character
repeat for difftool stuff and that's all I needed to make it work. No wrapper script or local remote variables were needed.

SourceTree Users: This could be your problem.
One possibility for SourceTree users encountering the problem described in this question: If you are having this problem from right-clicking in SourceTree and launching external merge tool (which internally runs something along the lines of git mergetool sourcetree), there is a SourceTree bug that causes it to hang when you are resolving a conflict where one side of the file has been deleted.
This is further complicated by the fact that SourceTree's UI does not clearly indicate that the reason for the conflict is that the file was removed on one side or the other.
You can confirm this by opening a terminal and running:
git mergetool
You'll see something like the following:
Deleted merge conflict for 'Stuff/Other/Thingamajig.js':
{local}: modified file
{remote}: deleted
Use (m)odified or (d)eleted file, or (a)bort?
This kicked my butt for over an hour, during which I ended up on this SO question, so I'm leaving my findings in this answer to help out the next poor soul that might fall victim to this bug.
(If you do encounter this issue, please consider following the link above and vote on the SourceTree bug so Atlassian will get a sense of the scale of this issue's impact.)

It seems to me that the problem is that the path that git bash is using is not the one that Windows is using. I checked that by running env | grep PATH from within git bash.
I understand you don't want to mess with the git installation, so I suggest that you give the complete path to your wrapper.
You have to give it using the cygwin format. How to do that?
1) Go to the place, where you have the wrapper, and run Git Bash there.
2) In the Git Bash window type pwd, which will show you current working directory. Right-click on the window title and select Mark. Using mouse select the path (in my case it's /C/Users/lpiepiora/cmds and hit Enter.
3) Now edit your .gitconfig and add the copied path to it (you have to add an extra slash at the end of the copied path).
After that steps, you should be able to launch your merge tool.
PS. You may want to change your git-diff-diffmerge-wrapper.sh to something along these lines, to handle properly removed / added files, as it was suggested in an answer to another question.
#!/bin/sh
NULL="/dev/null"
if [ "$2" = "$NULL" ] ; then
echo "removed: $1"
elif [ "$1" = "$NULL" ] ; then
echo "added: $2"
else
echo "changed: $3"
"C:\Program Files\SourceGear\Common\DiffMerge\sgdm.exe" "$1" "$2" | cat
fi

[diff]
tool = meld
[difftool]
prompt = false
[difftool "meld"]
cmd = "\"C:\\Program Files (x86)\\Meld\\Meld.exe\" \"$LOCAL\" \"$REMOTE\""
adding to the above answers. This is my git config for windows for making meld as diff tool
be careful with the "

Related

git mergetool throws an error "mv: cannot move <file> to <file_backup_3056>: function not implemented

I'm trying to setup Meld as my difftool as this is something I've used for a few years now and what I'm comfortable with.
As usual, I setup my meld on my PATH and put
[merge]
tool = meld
[diff]
guitool = meld
in my global config.
Now, when I do git mergetool upon conflicts, I get this strange error:
And my meld is opening up like this:
I've tried several variations of the difftool command like:
[mergetool "meld"]
cmd = meld.exe "$LOCAL" "$MERGED" "$REMOTE" --output "$MERGED"
cmd = meld "$LOCAL" "$BASE" "$REMOTE" --output "$MERGED"
(one of those at a time) and, while local works, base and remote doesn't work. Executing git mergetool produces these files in my local dir:
Which is in line with the first error - cannot mv or cp to things... how do I fix this please?
These "function not implemented" errors indicate that you're working in a file system that does not support the normal POSIX semantics that Git relies on. It's not clear precisely why you are getting these errors. Sometimes Docker goes crazy, some people report various issues with WSL, some versions of SMB/Samba will sometimes do this, and so on. (I mention WSL specifically because of your windows and git-bash tags.)
Once you're in this state, nothing in Git can fix it. If it's a Docker issue, restarting Docker may clear it up.
If you're working in a cloud-synced folder, don't do that: work in a local folder. Git needs the POSIX semantics, especially within the .git repository proper, and cloud-synced systems don't respect this.

Unabe to change git editor

I am trying to set the editor as the standard Notepad or even the Vim. However Git keeps showing me this message when I run git commit:
> hint: Waiting for your editor to close the file... error: cannot spawn
> notepad++.exe: No such file or directory
I uninstalled the current git version I had installed and installed the new version Git-2.36.1-64-bit however the error persists (I already did it for the second time: this time choosing Vim instead of Notepad, with no success... always the same notepad++ error message shown).
I tried to find any old git config files that may have notepad++ setted up but I didn't find any. At %userprofile% folder there is the file with no editor setted. At the installation folder, under /etc also there is no editor setted. I already reboot the computer (even between instalations) but always got the same message.
This may come from an old installation that used to had notepad++ as default editor, but I re-installed it again twice choosing different editors and nothing changes.
Running git config --list brings no core.editor setting.
I also already ran the command git config core.editor with the correct path of the notepad.exe and nothing happens (even with the --global option).
I also checked under the "Program Data" folder, but the git config file there also doesn't have any editor setted.
I ran out of options, any help will be appreciated
In your particular case the culprit here was that something (not sure what the "something" was / is) had set GIT_EDITOR in your environment. Using whatever command you need to unset the variable solved the problem.
Note that when Git goes to fire up an editor, it generally uses the first value from the following sequence of items, where $ indicates an environment variable and the lack of a dollar sign indicates a git config --get setting (git config --get can both get the setting and report whether it exists, and Git uses the latter internally):
$GIT_EDITOR
core.editor
$VISUAL
$EDITOR
If none of these succeed, Git falls back on the compiled-in-default.
(When using git rebase, Git adds $GIT_SEQUENCE_EDITOR and sequence.editor in to the front of the list before invoking any editor on the series of pick and other commands in the interactive rebase command sheet. This means you can write a script that uses interactive rebase, but doesn't open the regular editor on the pick command-sheet, yet still opens the regular Git editor on any to-be-edited commits.)
The command-line invocation:
git var GIT_EDITOR
will obtain and print out the name of the editor Git is programmed to use. In my case that's vim so git var GIT_EDITOR prints vim, but the command-line sequence:
(export GIT_EDITOR=example; git var GIT_EDITOR)
prints example instead since my shell set the environment variable GIT_EDITOR temporarily for the duration of that command.

Git print files in Windows Format

The most common use case I deal with git is to checkout file or remove or add file from Windows Command prompt.
I don't intend to use fancy gui tools. I like to work with keyboard and command prompt as much as possible.
So whenever I ask git status or any other report, git prints the file name like this
error: The following untracked working tree files would be overwritten by merge:
Tasks/Test/MyTest.js
The problem is, I can't just copy paste that text and use git checkout or git add anything. Since Windows can't understand / it expects you to give with \
Is there anyway git can print the info in Windows format or Windows can accept the *nix format [del Tasks/Test/MyTest.js]
I just tested Git using the Command Prompt and I had no trouble running git add on a file path which included forward slashes, so I don't see your problem as being reproducible.
Another option for you to consider is to use the Git Bash command line tool which ships with the Windows download of Git. The bash is a window, similar in appearance to the Command Prompt, but more powerful. On my Windows setup the Git Bash program is located here:
C:\Program Files\Git\git-bash.exe
The Git Bash tool does not make a distinction between / and \ in the path. Since either will work, you only need to copy the output you want, which is also easy and straightforward.
And good for you for sticking to command line Git. I believe you will become a stronger Git user by learning the nuts and bolts first on the command line.

Git with SSH on Windows

I've went through the excellent guide provided by Tim Davis which is about configuring Git to work with SSH under Windows in order to produce a Git Server in order to have a main place for my DVCS.
I am in the process of creating a clone for my project. I’ve went through all the steps till this point, but I keep getting this from TortoiseGit:
git.exe clone -v “ssh://Administrator#127.0.0.1:22/SSH/Home/administrator/myapp.git” “E:\GitTest\myapp”
bash: Administrator#127.0.0.1: command not found
Initialized empty Git repository in E:/GitTest/myapp/.git/
fatal: The remote end hung up unexpectedly
Success
and nothing gets cloned.
BTW: The TortoisePLink comes up just before this message appears and asks me: “login as:” ( I thought that this info is given in the command, i.e: Administrator#blahblah.
My home variable is set to the correct place:
From a Git Bash shell:
echo $HOME
/c/SSH/home/Administrator
I’ve also tried using Putty’s plink instead of TortoisePLink (in both Git’s and TortoiseGit’s installation). This time the error was narrowed down to:
git.exe clone -v “ssh://Administrator#127.0.0.1:22/c:/SSH/Home/administrator/myapp.git” “E:\GitTest\myapp”
Initialized empty Git repository in E:/GitTest/myapp/.git/
fatal: The remote end hung up unexpectedly
I fought with this problem for a few hours before stumbling on the obvious answer. The problem I had was I was using different ssh implementations between when I generated my keys and when I used git.
I used ssh-keygen from the command prompt to generate my keys and but when I tried "git clone ssh://..." I got the same results as you, a prompt for the password and the message "fatal: The remote end hung up unexpectedly".
Determine which ssh windows is using by executing the Windows "where" command.
C:\where ssh
C:\Program Files (x86)\Git\bin\ssh.exe
The second line tells you which exact program will be executed.
Next you need to determine which ssh that git is using. Find this by:
C:\set GIT_SSH
GIT_SSH=C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe
And now you see the problem.
To correct this simply execute:
C:\set GIT_SSH=C:\Program Files (x86)\Git\bin\ssh.exe
To check if changes are applied:
C:\set GIT_SSH
GIT_SSH=C:\Program Files (x86)\Git\bin\ssh.exe
Now git will be able to use the keys that you generated earlier.
This fix is so far only for the current window. To fix it completely you need to change your environment variable.
Open Windows explorer
Right-click Computer and select Properties
Click Advanced System Settings link on the left
Click the Environment Variables... button
In the system variables section select the GIT_SSH variable and press the Edit... button
Update the variable value.
Press OK to close all windows
Now any future command windows you open will have the correct settings.
Since this keeps coming up in search results for making git and github work with SSH on Windows (and because I didn't need anything from the guides above), I'm adding the following, simple solution.
(Microsoft says they are working on adding SSH to Visual Studio, and GitHub for Windows still doesn't support SSH...)
1. I installed "git for Windows" (which includes ssh and a bash shell)
https://git-scm.com/download/win
2. From the included bash shell (which, for me, was installed at: C:\Program Files\Git\git-bash.exe)
cd to the root level of where you want your repo saved (something like: C:\code\github\), and
Type:
eval $(ssh-agent -s) && ssh-add "C:\Users\YOURNAMEHERE\.ssh\github_rsa"
3. Type: (the SSH link from the repo)
git clone git#github.com:RepoName/Project.git
you are using a smart quote “ instead of " here:
git.exe clone -v “ssh://
^^^
Make sure you use the plain-old-double-quote.
I've found my ssh.exe in C:/Program Files/Git/usr/bin directory.
If Git for windows is installed, run Git Bash shell:
bash
You can run ssh from within Bash shell (Bash is aware of the path of ssh)
To know the exact path of ssh, run "where" command in Bash shell:
$ where ssh
you get:
c:\Program Files\Git\usr\bin\ssh.exe
I was trying to solve my issue with some of the answers above and for some reason it didn't work. I did switch to use the git extensions and this are the steps I did follow.
I went to Tools -> Settings -> SSH -> Other ssh client
Set this value to C:\Program Files\Git\usr\bin\ssh.exe
Apply
I guess that this steps are just the same explained above. The only difference is that I used the Git Extensions User Interface instead of the terminal. Hope this help.
When I typed where ssh it showed me multipe ssh.exe
user#pc MINGW64 /c/dev/
$ where ssh
C:\Users\user\AppData\Local\Programs\Git\usr\bin\ssh.exe
C:\Windows\System32\OpenSSH\ssh.exe
Deleting / moving these exe helped:
# copy from
# C:\Users\user\AppData\Local\Programs\Git\usr\bin
# to something like
# C:\Users\user\AppData\Local\Programs\Git\usr\bin\backup-ssh
ssh-agent.exe
ssh.exe
ssh-add.exe
This solved the issue for me.

How can I set up an editor to work with Git on Windows?

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?
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.
Configuring git 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 input
When 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:
How do I view ‘git diff’ output with visual diff program? for the general theory
How do I setup DiffMerge with msysgit / gitk? for another example of external tool (DiffMerge, and WinMerge)
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.
Building on Darren's answer, to use Notepad++ you can simply do this (all on one line):
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Obviously, the C:/Program Files/Notepad++/notepad++.exe part should be the path to the Notepad++ executable on your system. For example, it might be C:/Program Files (x86)/Notepad++/notepad++.exe.
It works like a charm for me.
Article How to set Notepad++ as the default Git editor for commits instead of Vim explains parameters of the command.
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.
Edit: After updating to Vim 7.3, I've come to the conclusion that the cleanest and easiest way to do this is:
Add Vim's main folder to your path (right click on My Computer → Properties → Advanced → Environment Variables)
Run this:
git config --global core.editor "gvim --nofork '%*'"
If you do it this way, then I am fairly sure it will work with Cygwin as well.
Original answer:
Even with a couple of Vim-related answers, I was having trouble getting this to work with gVim under Windows (while not using a batch file or %EDITOR% or Cygwin).
What I eventually arrived at is nice and clean, and draws from a few of the solutions here:
git config --global core.editor \
"'C:/Program Files/Vim/vim72/gvim.exe' --nofork '%*'"
One gotcha that took me a while is these are not the Windows-style backslashes. They are normal forward slashes.
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
For Atom you can do
git config --global core.editor "atom --wait"
and similar for Visual Studio Code
git config --global core.editor "code --wait"
which will open up an Atom or Visual Studio Code window for you to commit through,
or for Sublime Text:
git config --global core.editor "subl -n -w"
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).
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:
Created a one-line batch file (named git_editor.bat) which contains the following:
"C:/Program Files/Vim/vim72/gvim.exe" --nofork "%*"
Placed git_editor.bat on in my PATH.
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 ensures 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.
Edit .gitconfig file in c:\Users\YourUser folder and add:
[core]
editor = 'C:\\Program files\\path\\to\\editor.exe'
Thanks to the Stack Overflow community ... and a little research I was able to get my favorite editor, EditPad Pro, to work as the core editor with msysgit 1.7.5.GIT and TortoiseGit v1.7.3.0 over Windows XP SP3...
Following the advice above, I added the path to a Bash script for the code editor...
git config --global core.editor c:/msysgit/cmd/epp.sh
However, after several failed attempts at the above mentioned solutions ... I was finally able to get this working. Per EditPad Pro'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...
#!/bin/sh
"C:/Program Files/JGsoft/EditPadPro6/EditPadPro.exe" //newinstance "$*"
This is the one 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 information 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 - e.g. 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 in 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.
Vim/gVim works well for me.
>echo %EDITOR%
c:\Vim\Vim71\vim.exe
I needed to do both of the following to get Git to launch Notepad++ in Windows:
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 Notepad++ with the required permissions.
After doing both of the above, it worked.
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 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
git config --global core.editor 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 points 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.
Based on VonC's suggestion, this worked for me (was driving me crazy):
git config --global core.editor "'C:/Program Files (x86)/Sublime Text 3/subl.exe' -wait"
Omitting -wait can cause problems, especially if you are working with Gerrit and change ids that have to be manually copied to the bottom of your commit message.
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 X Window.
The Emacs keybindings don't work for me from a Windows shell, so I would only use this from a Cygwin shell... (rxvt is recommended.)
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 a DOS console and msysgit.
Say you want to configure VsCode to be your editor.
Do the following:
Add the following lines to your .gitconfig file:
The default location of .gitconfig file is C:\Users\USER_NAME\.gitconfig
[core]
editor = code -w -n
[diff]
tool = vscode
[difftool "vscode"]
cmd = code -w -n --diff $LOCAL $REMOTE
[merge]
tool = vscode
[mergetool "vscode"]
cmd = code -w -n $MERGED
NOTE:
-w is mandatory, and tells git to wait for vscode to load.
-n is optional, and tells git to open vscode in a new-window.
In case you want to configure a custom path to the editor in Windows:
You need to replace the word code with Path to '.exe' of VsCode.
For example:
[core]
editor = "'C:/Users/Tal/AppData/Local/Programs/Microsoft VS Code/Code.exe'" -w -n
[diff]
tool = vscode
[difftool "vscode"]
cmd = "'C:/Users/Tal/AppData/Local/Programs/Microsoft VS Code/Code.exe'" -w -n --diff $LOCAL $REMOTE
[merge]
tool = vscode
[mergetool "vscode"]
cmd = "'C:/Users/Tal/AppData/Local/Programs/Microsoft VS Code/Code.exe'" -w -n $MERGED
Note:
You need to surround the path with single-quotes ''.
The slashes in the path should be forward-slashes /.
Or another example:
[core]
editor = \"C:\\Users\\Tal\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" -w -n
[diff]
tool = vscode
[difftool "vscode"]
cmd = \"C:\\Users\\Tal\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" -w -n --diff $LOCAL $REMOTE
[merge]
tool = vscode
[mergetool "vscode"]
cmd = \"C:\\Users\\Tal\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" -w -n $MERGED
UPDATE:
VsCode supports now "3-way merges"!
The update was done in versions 1.69.0 and 1.70.0.
So now you can enable the VsCode "mergetool" to view 3-way merges.
To do so, you need to update the line:
[mergetool "vscode"]
cmd = code -w -n $MERGED
with the new line:
[mergetool "vscode"]
cmd = code -w -n --merge $REMOTE $LOCAL $BASE $MERGED
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 prefer to use Emacs. Getting it set up can be a little tricky.
Download Emacs and unpack it somewhere like c:\emacs.
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.
Add (server-start) somewhere in your .emacs file. See the Emacs Windows FAQ for advice on where to put your .emacs file.
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.
I managed to get the environment version working by setting the EDITOR variable using quotes and /:
EDITOR="c:/Program Files (x86)/Notepad++/notepad++.exe"
I've had difficulty getting Git to cooperate with WordPad, Komodo Edit 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. It 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.
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 Process Monitor 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.
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.
This works for PowerShell and cmder 1.2 (when used with PowerShell). In file ~/.gitconfig:
[core]
editor = 'c:/program files/sublime text 3/subl.exe' -w
How can I make Sublime Text the default editor for Git?
I found a a beautifully simple solution posted here - although there may be a mistake in the path in which you have to copy over the "subl" file given by the author.
I am running Windows 7 x64, and I had to put the "subl" file in my /Git/cmd/ folder to make it work.
It works like a charm, though.
Atom and Windows 10
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
to add sublime git config --global core.editor "'C:\Program Files\Sublime Text 3\sublime_text.exe'"
I solved a similar issue using GIT_EDITOR variable and notepad2 as editor.
Solution 1: Set the environment variable GIT_EDITOR to C:/tools/notepad2.exe. This works nicely, but git complains if the commit message has non-ASCII characters.
Solution 2: Set GIT_EDITOR to C:/tools/notepad2.exe //utf8. Notice the double slash in front of the program switch. BTW: -utf8 would have worked as well.

Resources