Charlie Harvey

Quick tip: Using vimdiff with git

Vimdiff is an amazing tool to work with file differences and it particuarly suitable for use when examining differences between git revisions. There is a command built in to git that is called git-difftool. It allows you to use an external tool to look at your diffs this tip just shows how I like to configure git-difftool.

You can have a look at the possible tools to use by typing $ git difftool --tool-help On my system this gives 'git difftool --tool=<tool>' may be set to one of the following: araxis gvimdiff gvimdiff2 vimdiff vimdiff2 The following tools are valid, but not currently available: bc3 codecompare deltawalker diffmerge diffuse ecmerge emerge kdiff3 kompare meld opendiff p4merge tkdiff xxdiff Some of the tools listed above only work in a windowed environment. If run in a terminal-only session, they will fail.

I like to make vimdiff the default diffing tool for the text environment and gvimdiff if I want a gui. $ git config --global diff.tool vimdiff $ git config --global digg.guitool gvimdiff

By default git-difftool prompts before launching the diff tool. Which is annoying, so I like to disable it with $ git config --global difftool.prompt 0

Now I can use git-difftool thus, assuming I am in a directory tht is under version control by git $ git difftool . If I want to launch it graphically I can add -g to the command like thisgit difftool -g .

Now, typing difftool is rather longwinded, so I like to make a couple of quick aliases for convenience $ git config --global alias.vd difftool $ git config --global alias.gv 'difftool -g' Now that is all set up I can review my changes with a simple $ git gv Sorted.

Using vimdiff as the git difftool


  • Be respectful. You may want to read the comment guidelines before posting.
  • You can use Markdown syntax to format your comments. You can only use level 5 and 6 headings.
  • You can add class="your language" to code blocks to help highlight.js highlight them correctly.

Privacy note: This form will forward your IP address, user agent and referrer to the Akismet, StopForumSpam and Botscout spam filtering services. I don’t log these details. Those services will. I do log everything you type into the form. Full privacy statement.