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

后端 未结 6 1171
一整个雨季
一整个雨季 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 20:49

    When rebasing, I strongly recommend switch $theirs and $mine, because it is different when you merge and rebase-merge. Check here:

    What is the precise meaning of "ours" and "theirs" in git?

    So, if you only use mergetool to rebase like me, do:

    [mergetool "tortoisemerge"]
    cmd = \""c:/Program Files/TortoiseGIT/bin/TortoiseGitMerge.exe"\" -base "$BASE" -theirs "$LOCAL" -mine "$REMOTE" -merged "$MERGED"
    
    0 讨论(0)
  • 2021-01-30 20:57
    [diff]
      tool = tortoisediff
    [difftool]
      prompt = false
    [merge]
      tool = tortoisemerge
    [mergetool]
      prompt = false
      keepBackup = false
    [difftool "tortoisediff"]
      cmd = \""C:/Users/$USER/Desktop/TortoiseMerge.exe"\" -base:\"$BASE\" -mine:\"$LOCAL\" -theirs:\"$REMOTE\" -merged:\"$MERGED\"
    [mergetool "tortoisemerge"]
      cmd = \""C:/Users/$USER/Desktop/TortoiseMerge.exe"\" -base:\"$BASE\" -mine:\"$LOCAL\" -theirs:\"$REMOTE\" -merged:\"$MERGED\"
    

    This worked for me, using TortoiseMerge 1.6.7 (Portable)

    0 讨论(0)
  • 2021-01-30 21:05

    The following settings work fine for me. However, I am using TortoiseGit not TortoiseSVN. Notice the difference in the parameters for diff.

    [diff]
      tool = tortoisediff
    [difftool]
      prompt = false
    [merge]
      tool = tortoisemerge
    [mergetool]
      prompt = false
      keepBackup = false
    [difftool "tortoisediff"]
      cmd = \""c:/Program Files/TortoiseGIT/bin/TortoiseGitMerge.exe"\" -mine "$REMOTE" -base "$LOCAL"
    [mergetool "tortoisemerge"]
      cmd = \""c:/Program Files/TortoiseGIT/bin/TortoiseGitMerge.exe"\" -base "$BASE" -theirs "$REMOTE" -mine "$LOCAL" -merged "$MERGED"
    
    0 讨论(0)
  • 2021-01-30 21:07

    So that filenames with spaces are handled correctly, you should change the last line of @melbourn's answer to

    cmd = \""c:/Program Files/TortoiseGIT/bin/TortoiseGitMerge.exe"\" -base "$BASE" -theirs "$REMOTE" -mine "$LOCAL" -merged "$MERGED"
    
    0 讨论(0)
  • 2021-01-30 21:11

    For using the TortoiseMerge with an existing TortoiseSVN installation in Windows:

    [guitool "VisualDiff"]
        cmd = git difftool -y \"$FILENAME\"
        needsfile = yes
        noconsole = yes
    [diff]
        tool = tortoisediff
    [difftool]
        prompt = false
    [merge]
        tool = tortoisemerge
    [mergetool]
        prompt = false
        keepBackup = false
    [difftool "tortoisediff"]
        cmd = \""W:/Programs/TortoiseSVN/bin/TortoiseMerge.exe"\" "/mine:$REMOTE" "/base:$LOCAL"
    [mergetool "tortoisemerge"]
        cmd = \""W:/Programs/TortoiseSVN/bin/TortoiseMerge.exe"\" "/base:$BASE" "/theirs:$REMOTE" "/mine:$LOCAL" "/merged:$MERGED"
    
    0 讨论(0)
  • 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.
    0 讨论(0)
提交回复
热议问题