May 17, 2009 by Jonathan Palardy

What happens when you type git diff ? As with all interesting questions, the answer is “it depends…”

Here’s one thing you want git to do:



Vimdiff!

Step 1: add this to your .gitconfig



[diff]

external = git_diff_wrapper

[pager]

diff =



Step 2: create a file named git_diff_wrapper , put it somewhere in your $PATH



#!/bin/sh vimdiff " $2 " " $5 "

I still have access to the default git diff behavior with the --no-ext-diff flag. Here’s a function I put in my bash configuration files:



function git_diff() {

git diff --no-ext-diff -w " $@ " | vim -R –

}



--no-ext-diff : to prevent using vimdiff

-w : to ignore whitespace

-R : to start vim in read-only mode

– : to make vim act as a pager

When it comes to vimdiff, you can get started with this tutorial.