Click here to Skip to main content
15,885,216 members
Articles / DevOps / Git
Tip/Trick

Git + WinMerge + Cygwin

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
1 Jul 2010CPOL1 min read 19.3K   3  
How to use WinMerge to view diffs with Git under Cygwin

Background


This took me a good half day to figure out so I thought it'd be useful to others in a similar situation. It's derived from this post on StackOverflow[^]. You can find more details there but I did have to make a few changes to get it fully working both under Cygwin and a plain Windows command prompt.

Last I checked this was working under:

    • Git 1.7.0.4

    • WinMerge 2.12.4.0

    • Cygwin 1.7.5

    • Windows 7 x64



Tying WinMerge to Git



    • Add the following lines to your .gitconfig file:
      [diff]
        tool = winmerge
      [difftool "winmerge"]
        cmd = git-difftool-winmerge-wrapper.sh \"$LOCAL\" \"$REMOTE\"
      [difftool]
        prompt = false

      The last option (prompt = false) is optional. You can omit it if you do want Git to prompt you before opening each diff.

    • Create a file named git-difftool-winmerge-wrapper.sh and place it in your path. I just dropped it in my home directory. You can change the default Cygwin path to include your home directory by modifying the .bash_profile file (also in your home directory) and adding PATH=${PATH}:${HOME}

    • Add the following to git-difftool-winmerge-wrapper.sh:
      Bash
      #!/bin/sh
      echo "Launching WinMergeU.exe \"$(cygpath -aw "$1")\" \"$(cygpath -aw "$2")\""
      if [ -f $1 -a -f $2 ]
      then
        "C:/Program Files (x86)/WinMerge/WinMergeU.exe" -e -u -wl -dl "Base" -dr "Mine" "$(cygpath -aw "$1")" "$(cygpath -aw "$2")"
      else
        echo "skipping as one file doesn't exist"
      fi

      Obviously, you may need to adjust the WinMerge installation folder to your local install path.



Running under Cygwin


Just run git difftool.

Running under Windows command prompt


Ensure you have all necessary files in your path:

    • Git binaries

    • git-difftool-winmerge-wrapper.sh

    • WinMerge executable


Run git difftool.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Canada Canada
me code

Comments and Discussions

 
-- There are no messages in this forum --