Git difftool not launching external DiffMerge program
Asked Answered
A

6

12

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.

Antibes answered 12/6, 2014 at 21:58 Comment(11)
Have you got Cygwin installed too?Intoxication
Nothing in the blog post indicated that it was necessary. In fact, the first comment seems to indicate that it's not.Antibes
Did you try with the latest 2.0 msysgit "Git for Windows"? github.com/msysgit/msysgit/releasesMccahill
@Mccahill - there's a ton of configuration in our git install; I'm nervous about trying to upgrade it outside the corporate install. Supposedly the process should work with any version of git above 1.6.3. Also, not sure where you're seeing 2.0; the link you provide shows a new (probably unstable) 1.9.4 preview.Antibes
Don't upgrade. Don't touch anything. Use the portable ditrib (github.com/msysgit/msysgit/releases/download/…), which is an archive that you can uncompress anywhere. That way, you can fallback to your current git if the new one doesn't solve anything.Mccahill
Thanks. So I run this somewhere other than my current version, and then follow all the instructions in the original post? And if it does work, then what?Antibes
If it works, you should be able to use the recent install without major issue. You will also report that to the admins, for them to decide of an upgrade path.Mccahill
It's trying to execute your shell script (git-diff-diffmerge-wrapper.sh) and not finding it. Try executing it yourself from a command prompt.Tahr
If you update to git v1.8+ you will get the --dir-diff option to difftool. That will allow full directory comparisons (ie: you won't have to go through each file 1 at a time).Landrum
Your problem is very likely that you are using "\" (backslash) when you need to be using "/" (forward slash) in your command path. Remember, in shell scripts '\' is an escape character, not a path separator.Landrum
@ShadowCreeper - I tried switching to forward slashes and get the same results.Antibes
C
9

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\""
Coh answered 21/6, 2014 at 2:18 Comment(3)
Thank you! I copied the DiffMerge path from your example to my .gitconfig file (with slashes the way you have them) and it works. So does this mean I don't need the wrapper file that the blog post used?Antibes
@Antibes that's correct, you don't need the wrapper file...at least as far as I know. I never needed to use a wrapper file personally.Coh
I was trying to use some of the other answers changing the paths to bcomp.exe for bc but they weren't working... (using mingw64). I copied and pasted this, changed bc3 to bc4 (since I'm using bc4) and it just worked. Thank you very much.Wanids
T
11

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.

Tortfeasor answered 29/5, 2018 at 21:32 Comment(3)
thank you a lot. I spent an hour and you helped me.Darg
I know this is old but in case anybody ends up here (as someone obviously did), what you wanted was git difftool --cached to seee the diff of the cached files.Wanids
OMG! Cost me at least 15 min. Doh!! THANK YOU! Now. How do I replace all that hair I just pulled out? ;)Stanchion
C
9

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\""
Coh answered 21/6, 2014 at 2:18 Comment(3)
Thank you! I copied the DiffMerge path from your example to my .gitconfig file (with slashes the way you have them) and it works. So does this mean I don't need the wrapper file that the blog post used?Antibes
@Antibes that's correct, you don't need the wrapper file...at least as far as I know. I never needed to use a wrapper file personally.Coh
I was trying to use some of the other answers changing the paths to bcomp.exe for bc but they weren't working... (using mingw64). I copied and pasted this, changed bc3 to bc4 (since I'm using bc4) and it just worked. Thank you very much.Wanids
A
3

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.

Agateware answered 7/1, 2016 at 22:27 Comment(0)
U
3

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

Unparalleled answered 12/6, 2018 at 3:26 Comment(0)
K
1

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.

Step 1

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.

Step 2

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

Step 3

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
Kliber answered 20/6, 2014 at 21:52 Comment(2)
I'm not using cygwin. Why do I need to use cygwin format?Antibes
The script to handle removed or added files gives me this error: /mingw64/libexec/git-core/git-mergetool--lib: line 124: changed: MyProject/hello.py: No such file or directory. Line 124 in git-mergetool--lib is an eval. Is there a way to avoid the error message? Otherwise it works well.Earleneearley
N
-1
[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 "

Nitroso answered 25/3, 2020 at 18:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.