Git difftool not launching external DiffMerge program

本小妞迷上赌 提交于 2019-12-07 01:40:30

问题


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.


回答1:


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



回答2:


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.




回答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.




回答4:


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




回答5:


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


来源:https://stackoverflow.com/questions/24194569/git-difftool-not-launching-external-diffmerge-program

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