Git difftool not launching external DiffMerge program

戏子无情 提交于 2019-12-05 04:16:47

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\""

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.

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

lpiepiora

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!