Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

vim

vimdiff

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?

like image 766
Lai Yu-Hsuan Avatar asked Sep 05 '11 14:09

Lai Yu-Hsuan


People also ask

How do I resolve merge conflicts in Mergetool git?

We can manually resolve the merge conflict by editing the content in the bottom pane, and then saving the file using :wqa (Write and Quit all files). Once the conflict resolution is successful, the merged file will be staged for commit. git commit -m 'Merged from multiple branches' .


2 Answers

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 "Gvdiffsplit!" "$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.

like image 96
Peter Rincker Avatar answered Sep 29 '22 12:09

Peter Rincker


After lots of research for issuing mergetool with vimdiff and only 3 windows, I came up with this configuration, that allows me to chose when I want 3 windows or the default 4 windows:

git config --global merge.tool vimdiff git config --global alias.mt mergetool  git config --global mergetool.merge3.cmd 'vim -d -c "wincmd l" "$LOCAL" "$MERGED" "$REMOTE"' git config --global alias.m3 'mergetool -t merge3' 

Now you can start 3 windows just typing:

git m3 

And the default (4 windows) will still works as expected with:

git mt 

Also, you probably would like to add this lines to the end of your ~/.vimrc or /etc/vim/vimrc

 " shortcuts to vimdiff  let mapleader=','  let g:mapleader=','   if &diff     map <leader>1 :diffget LOCAL<CR>     map <leader>2 :diffget BASE<CR>     map <leader>3 :diffget REMOTE<CR>  endif 

This will create shortcuts like ,1 to grab from left, ,3 to grab from right (in both modes) and also ,2 to grab from base (center window) in the 4 windows mode.

That helps a lot!

My ~/.gitconfig file looks like this:

[user]         name = Dr Beco         email = my@email [merge]         tool = vimdiff [mergetool "merge3"]         cmd = vim -d -c \"wincmd l\" \"$LOCAL\" \"$MERGED\" \"$REMOTE\" [alias]         lo = log --pretty=format:\"%h %ce %cd %s\" --graph         co = checkout         ci = commit         cm = commit -a -m         st = status         br = branch         m3 = mergetool -t merge3         mt = mergetool [diff]         tool = vimdiff 

I hope this helps you (and those who get to here).

like image 40
DrBeco Avatar answered Sep 29 '22 10:09

DrBeco