developer | thinker | tinkerer

Drinking The Git Kool Aid - Glass 2 - Diff

In our last post we ran over the basics and I encouraged you to become familiar with the Git command line.

One thing I immediately missed was being able to do diffs like I could within TortoiseSVN to easily see what I had changed. Git will do diffs but I wanted to be able to use Beyond Compare.

In my previous post I used the following example:

[D:\wwwroot\pelican]git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#       modified:   content/2013-05-13-installing-railo-coldfusion-iis.markdown

So we know that the file change but not WHAT changed within that file.

You can easily run Git's built in diff:

[D:\wwwroot\pelican]git diff content/2013-05-13-installing-railo-coldfusion-iis.markdown
diff --git a/content/2013-05-13-installing-railo-coldfusion-iis.markdown b/content/2013-05-13-
index 476528e..995d44e 100644
--- a/content/2013-05-13-installing-railo-coldfusion-iis.markdown
+++ b/content/2013-05-13-installing-railo-coldfusion-iis.markdown
@@ -25,7 +25,7 @@ Edit your hosts file (C:\Windows\System32\drivers\etc\hosts) and add the fol
* Click Control Panel > Programs > Turn Windows Features on or off.
* Install IIS with these options

But that gets messy and for long files or complex changes I find it very hard to read.

Wouldn't it be nice if we could tell Git to use another diff tool? Turns out you can!

I'm on Windows and Git stores all it's configuration in a simple text file.

Mine lives at: C:\Users\Jim.gitconfig

You can crack that file open with any text editor and add/tweak some useful things.

If you just installed Git your config file probably looks like this:

    name = Jim Priest
    email =

I have Beyond Compare already installed so all we need to do is add a few bits to tell Git to use Beyond Compare:

(I didn't come up with this on my own btw, I found the answer on Stack Overflow and have included that URL below)

Add the following to your .gitconfig file:

#Use BeyondCompare for diff

    tool = beyondcompare3
    prompt = false
[difftool "beyondcompare3"]
    #use cygpath to transform cygwin path $LOCAL (something like /tmp/U5VvP1_abc) to windows path, because beyondcompare3 is a windows software
    cmd = \"c:/program files/beyond compare 3/bcomp.exe\" "$LOCAL" "$REMOTE"
    tool = beyondcompare3
    prompt = false
[mergetool "beyondcompare3"]
    #trustExitCode = true
    cmd = \"c:/program files/beyond compare 3/bcomp.exe\" "$LOCAL" "$REMOTE" "$BASE" "$MERGED"

So this will allow you to use Beyond Compare for both diffs and merges (which you will eventually run into).

So now instead of doing 'git diff' do 'git difftool' (we'll discuss aliases in out next post):

D:\wwwroot\pelican]git difftool content/2013-05-13-installing-railo-coldfusion-iis.markdown

And Beyond Compare should open with changed files.

Drinking The Git Kool Aid - Glass 1 Drinking The Git Kool Aid - Glass 3 - Aliases

More like this...