259

I setup git diff to wrap into vimdiff, using "Git Diff with Vimdiff" as a guide, and it's working as expected unless there are many files with changes.

When there are multiple files with changes and I run git diff, it opens the first file and, after quitting the first instance of vimdiff, I'm presented with the following message:

external diff died, stopping at filename

This is a completely different behavior than I am used to. I had a similar setup in the past with SVN and, when diffing against multiple files, I would review the first file, then write and quit using :wq and the next file with differences would open up.

This is not the case with Git. I tried :n[ext], but doing so does not fill the left window with the original file so that it can be diffed against the modified version.

the Tin Man
161k44 gold badges222 silver badges308 bronze badges
asked Sep 14, 2010 at 23:54

5 Answers 5

414
git config --global diff.tool vimdiff
git config --global difftool.prompt false

Typing git difftool yields the expected behavior.

Navigation commands,

  • :qa in vim cycles to the next file in the changeset without saving anything.

Aliasing (example)

git config --global alias.d difftool

.. will let you type git d to invoke vimdiff.

Advanced use-cases,

  • By default, git calls vimdiff with the -R option. You can override it with git config --global difftool.vimdiff.cmd 'vimdiff "$LOCAL" "$REMOTE"'. That will open vimdiff in writeable mode which allows edits while diffing.
  • :wq in vim cycles to the next file in the changeset with changes saved.
Shyam Habarakada
15.9k3 gold badges39 silver badges47 bronze badges
answered Sep 15, 2010 at 0:27
Sign up to request clarification or add additional context in comments.

9 Comments

Just my two cents: I have df aliased to diff and dt aliased to difftool. Also, typing :qa in Vim will cycle to the next changeset without saving anything.
This solution is great except that when saving changes you have to type ":w!" instead of :w
@jonyamo Setting alias should be always based on how often we are using some commands. I am often using git diff than git difftool. So I have aliased d to 'diff' and 'dt' to difftool'. Usability is matter than creating aliases with pattern.
@Asenar "This solution is great except that when saving changes you have to type :w! instead of :w". That is because git calls vimdiff with the -R option. You can override it with git config --global difftool.vimdiff.cmd 'vimdiff "$LOCAL" "$REMOTE"'. That will open vimdiff in writeable mode.
Moved some of these upvoted comments into the answer. Thanks.
|
112

You can try git difftool, it is designed to do this stuff.

First, you need to config diff tool to vimdiff

git config diff.tool vimdiff

Then, when you want to diff, just use git difftool instead of git diff. It will work as you expect.

Undo
25.7k38 gold badges114 silver badges132 bronze badges
answered Sep 15, 2010 at 0:08

2 Comments

Almost there! Modified a bit it's exactly what I'm looking for. +1 though!
The vimdiff mergetool has recently been updated: git.kernel.org/?p=git/… (and a few other commits, but that's the biggest one). Not sure when the next maintenance release will be, but if you're willing to build from git.git, upgrades shall be yours!
25
Git accepts kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge,
and opendiff as valid diff tools. You can also set up a custom tool. 
git config --global diff.tool vimdiff
git config --global diff.tool kdiff3
git config --global diff.tool meld
git config --global diff.tool xxdiff
git config --global diff.tool emerge
git config --global diff.tool gvimdiff
git config --global diff.tool ecmerge
answered Jul 9, 2013 at 6:05

3 Comments

You answer for the mergetool, not the difftool. But it is still a helpful answer. +1.
@dotancohen Really Thanks i have never notice that on silly mistake now i can edit my answer.
@NanheKumar, @dotancohen, replacing merge with diff in the above answers will do the trick, i.e. git config --global diff.tool vimdiff.
17

If you want to permanently use vimdiff for git diff, you can set the ~/.gitconfig file:

git config --global diff.tool vimdiff

and then you can use git difftool to diff.

If you only want to temporarily use vimdiff, you can run the command every time:

git difftool --tool=vimdiff
answered May 13, 2021 at 11:24

1 Comment

I was indeed looking for a temporary solution. Thank you for that last addition.
6

For people who want to use another diff tool not listed in git, say with nvim. here is what I ended up using:

git config --global alias.d difftool -x <tool name>

In my case, I set <tool name> to nvim -d and invoke the diff command with

git d <file>
ssc-hrep3
16.3k8 gold badges51 silver badges96 bronze badges
answered Apr 19, 2020 at 4:11

1 Comment

nvimdiff is now supported as a tool so you could do git config --global diff.tool nvimdiff.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.