Git visual diff with Vimdiff

Basic git diff

The most commonly used form is simply git diff; this shows the changes that are not currently staged for the next commit. If you’ve already staged changes, git diff –cached will show the difference between the index and the last commit.

Typing git diff branch will show a diff between the current working directory and the named branch whilst git diff –stat shows an overview of changes.

Visial git diff

It’s fairly easy to get Vimdiff working with Git. Git has a lot of options for working with diffs, and one is diff.tool. Also related is the merge.tool setting which can be set to allow Vimdiff to be used as the merge resolution program.

These settings can be passed to Git without changing any configuration files:

git difftool --tool=vimdiff --no-prompt

To tell Git to always use Vimdiff, issue the following commands:

git config --global diff.tool vimdiff
git config --global merge.tool vimdiff

Omit –global if you just want to set these for the repository in the working directory. Now typing git difftool should bring up Vimdiff.

Another useful option is difftool.prompt, this will stop Vim prompting about launching vimdiff:

git config --global difftool.prompt false

If you’re just trying these commands out, then the prompt will seem annoying, but there are cases where you might want to ignore a few files so it can be useful.

Source:  http://usevim.com/2012/03/21/git-and-vimdiff/

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>