Why does git mergetool open 4 windows in vimdiff? (I'd expect 3)
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.
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).
Modifying a bit the commands from this page:
git config --global mergetool.vimdiff3.cmd 'vim -f -d "$LOCAL" "$MERGED" "$REMOTE"'
git config --global merge.tool vimdiff3
- 'Merged' would be your working copy.
- 'Local' the file that is in the branch you are trying to make the changes
- 'Remote' the file from the branch you are trying to merge with.
And then you execute the command: git mergetool
.
Note: I use fugitive also and highly recommend it.