jump to navigation

Setting up SourceGear’s DiffMerge with Git on Windows 7 March 29, 2013

Posted by Tournas Dimitrios in PHP.

Git is an open source version control system (VCS) , a command line tool for keeping a history on the state of your source code projects . It is fully distributed , which means that it can work almost entirely offline (compared to other VCS-tools like Subversion) .  As Git is primarily a command line tool , developers with a *nix  background will love it immediately . Those developers that doesn’t like the sentence “terminal”  have the option to use  GUI alternatives  (of course , with a subset of functionality) , which  act as frond-ends on top of Git’s command tool . A third option is to combine Git’s command tool with a few GUI applications  , for instance , replacing Git’s default text-editor (Vim) with Notepad++ ) .  This article will demonstrate how to configure  a GUI-based diff-editor to track differences between versions of an file . A Windows 7 is used to demonstrate the installation process , the same concepts apply on all Operating systems though .

DiffMerge is a cross-platform GUI-application to visually compare and merge files and folders .

Let’s stop for a minute to see how the git diff command can be used to show you the difference between the version of a file in the working directory , the stage and the most recent commit (or any commit made in the past) . The 3 main types of git diff commands you would likely use are :

  1. git diff   filename.php  :  Shows differences between the current state of a file in your working directory and the same file that was staged previously . 
  2. git diff  – -staged  filename.php :  Shows differences between a staged file  and its most recent ancestor (commit hystory) .
  3. git diff HEAD  – –  filename.php  : Shows the differences between a file in the working directory and its ancestor in the most recent commit  .


The above screen-shot shows which lines were removed (in red color) and added (in green color) into the new version of the index.html file . Although it is handy to have a quick view of the current state of a file compared with its ancestor , a graphical representation is most likely a better approach .  Lets see how simple it is to configure Git to show the diffs into “DiffMerge” .

  • The first step is to install  “DiffMerge” on our machine  . 
  • Install msys|Git  : Its an environment for Windows offering a Unix-type shell and a Perl interpreter . Because many parts of Git are still not programmed in C , but instead shell and Perl scripts , Git for Windows needs such an environment .
  • Set path of DiffMerge into msysgit’s PATH : Open C:\Program Files\Git\etc\profile and append (on bottom of the file) –>
    export PATH=$PATH:”/c/Program Files/SourceGear/Common/DiffMerge”
  • Open msysgit’s console and run the following commands :  
    1. git config –global diff.tool diffmerge
    2. git config –global difftool.diffmerge.cmd ‘diffmerge “$LOCAL” “$REMOTE”‘
    3. git config –global merge.tool diffmerge
    4. git config –global mergetool.diffmerge.cmd ‘diffmerge –merge –result=”$MERGED” “$LOCAL” “$(if test -f “$BASE”; then echo “$BASE”; else echo “$LOCAL”; fi)” “$REMOTE”‘

Finally , open msyGit’s terminal create a project with a few commits and try to compare different versions of a file  :


Accept (with a “y”) and msysGit  spawns the graphical DiffMerge application as seen on the following screenshot :



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s