Can TortoiseMerge be used as a difftool with Windows Git Bash?

后端 未结 6 1179
一整个雨季
一整个雨季 2021-01-30 20:37

I\'m just starting to work with Git. I would like to use TortoiseMerge as the difftool and mergetool.

In my $HOME/.gitconfig I have the following sections.

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-30 21:14

    Great answer by Klas Mellbourn! Saved me a lotta time. One shortcoming is, newly Added or Removed files in the repository will not show up during the difftool command execution. There's nothing to compare them to! Here's what I did on top of this: (Inspired by my co-worker's answer).

    1. Create a file named empty.empty in $Home directory (execute start ~ in your bash). And as the name suggests, keep it empty.
    2. Create another file named tortoisediff.sh in $Home/bin directory with following content

    :

    #!/bin/sh
    # $LOCAL $REMOTE seem to be swapped
    # $1 is $LOCAL
    # $2 is $REMOTE
    
    difftool='/c/Program Files/TortoiseGit/bin/TortoiseGitMerge.exe'
    NULL="/dev/null"
    empty="C:/home/empty.empty"
    
    if [ "$1" == "$NULL" ]; then
        echo "Added: " "$2"
        "$difftool" /base:"$empty" /mine:"$2" /readonly:"$empty"
    elif [ "$2" == "$NULL" ]; then
        echo 'Removed: ' "$1"
        "$difftool" /base:"$1" /readonly:"$1" /mine:"$empty"
    else
        echo 'Modified' "$2"
        "$difftool" /base:"$1" /basename:"$1" /readonly:"$1" /mine:"$2" /minename:"$2"
    fi
    
    # Checkout https://tortoisegit.org/docs/tortoisegitmerge/tme-automation.html for more
    
    1. Modify your .gitconfig file (Line 11 of the answer)

      cmd = tortoisediff.sh "$LOCAL" "$REMOTE"

    This would now make difftool refer to tortoisediff.sh instead of opening the application directly.

    1. Keep in mind: you'd have to run git add . followed by git difftool --staged instead of simply git difftool.

提交回复
热议问题