Why does git mergetool open 4 windows in vimdiff? (I'd expect 3)

Lai Yu-Hsuan picture Lai Yu-Hsuan · Sep 5, 2011 · Viewed 12k times · Source

When I met a conflict, I tried to use git-mergetool to solve it. I typed:

>git mergetool -t vimdiff

It opened vimdiff in 4-way, not 3-way. My split windows in vimdiff look like:

:ls
  1 #a   "Gemfile.lock"                 line 1
  2 %a   "Gemfile.lock.LOCAL.4828.lock" line 1
  3  a   "Gemfile.lock.BASE.4828.lock"  line 0
  4  a   "Gemfile.lock.REMOTE.4828.lock" line 0

What are they? I want a 3-way diff: target file, merge file and working file. How should I configure my git or vimdiff?

Answer

Peter Rincker picture Peter Rincker · Sep 6, 2011

As an alternative, have you thought about using fugitive?

I'm not going to lie to you; fugitive.vim may very well be the best Git wrapper of all time.

There is a an excellent vimcast, Fugitive.vim - resolving merge conflicts with vimdiff, by Drew Neil. This is part of a series on fugitive.

The Vimcasts website is a good place to learn more about vim.

To use fugitive as you mergetool you can use the following.

git config --global mergetool.fugitive.cmd 'vim -f -c "Gdiff" "$MERGED"'
git config --global merge.tool fugitive

Note: you may want to change vim to mvim or gvim.

Fugitive has a lot more to offer than just being a merge tool script so make sure you read the documentation and/or check out the vimcasts.