What's the difference between vimdiff and vimdiff2 in git?

nomadStack picture nomadStack · Jan 12, 2015 · Viewed 9.2k times · Source

What's the difference between them? My search engine results talk only about vimdiff, yet the command

git mergetool 

offers me both.

Answer

VonC picture VonC · Jan 12, 2015

vimdiff2 was introduced in commit 0008669 (Sept 2010, for git 1.7.4)

It is like vimdiff, but with different merge options (as commented in commit b2a6b71, git 1.8.2: "vimdiff and vimdiff2 differ only by their merge command").

It (vimdiff2) forces a 2-way merge, versus vimdiff which will use a 3-way merge if the base (common ancestor) is detected:

gvimdiff|vimdiff)
    if $base_present
    then
        "$merge_tool_path" -f -d -c 'wincmd J' \
            "$MERGED" "$LOCAL" "$BASE" "$REMOTE"
    else
        "$merge_tool_path" -f -d -c 'wincmd l' \
            "$LOCAL" "$MERGED" "$REMOTE"
    fi
    ;;
gvimdiff2|vimdiff2)
    "$merge_tool_path" -f -d -c 'wincmd l' \
        "$LOCAL" "$MERGED" "$REMOTE"
    ;;

Note that commit 7c147b7 (April 2014, for Git 2.1.0 August 2014) actually introduces vimdiff3 as well:

It's similar to the default, except that the other windows are hidden.
This ensures that removed/added colors are still visible on the main merge window, but the other windows not visible.

Specially useful with merge.conflictstyle=diff3.