1

I've been thinking of ways to visualize git commits with vim. I would like to be able to:

  1. run a command from the terminal such as: vimdiff -c <commit id>.
  2. vim opens with two windows on a vertical split layout, displaying a diff the changes introduced for one of the files on that particular commit.
  3. each file opens on a different tab, so I can press gt to view the diff for the next file.

I can't possibly be the first to think of this issue, but I couldn't find any plugin or information out there. So how do you guys do it?

1 Answer 1

3

Git provides this functionality for you.

First set up git to use Vim as its "difftool". (Depending on what you have installed, this step may be unnecessary: vimdiff is one of Git's default difftools.)

git config diff.tool vimdiff

Then run git's difftool command with appropriate options. e.g. to view the changes introduced by commit 12345abc, you can use either

git difftool 12345abc^..12345abc

or its shorthand

git difftool 12345abc^!

By default this will open the files one at a time. After you quit Vim, Git will open the next comparison. Here are a selection of ways to get Git instead to open all the diffs at once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.