How can I make WinMerge my git mergetool?

后端 未结 12 1678
既然无缘
既然无缘 2020-12-02 06:48

I\'m trying to integrate WinMerge with Git as I\'ve seen others done before on Windows 7 Ultimate.

I\'ve followed the following steps, but an error continues to show

相关标签:
12条回答
  • 2020-12-02 07:07

    This is easier to do and is what worked for me:

    git config --global diff.tool winmerge
    
    git config --replace --global difftool.winmerge.cmd "\"C:\path to winmerge\WinMergeU.exe\" -e -u -dl \"Base\" -dr \"Mine\" $LOCAL $REMOTE"
    
    git config --global difftool.prompt false
    
    0 讨论(0)
  • 2020-12-02 07:11

    To do WinMerge as compare and merge tool for Visual Studio 2017 Git Plugin:

    From windows command prompt: type >> git config --global --edit which will open the .getconfig file to edit.

    Please update with below command:

    [mergetool]
       prompt = false
       keepBackup = false
       keepTemporaries = false
    [merge]
       tool = winmerge
       [mergetool "winmerge"]
       name = WinMerge
       trustExitCode = true
       cmd = \"C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe\" -e -u -dl \"Base\" -dr \"Mine\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
    [diff]
       tool = winmerge
       [difftool "winmerge"]
       name = WinMerge
       trustExitCode = true
       cmd = \"C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe\" -u -e $LOCAL $REMOTE
    
    0 讨论(0)
  • 2020-12-02 07:11

    Your path is incorrect, it should be "/c/Program Files (x86)/WinMerge/WinMergeU.exe".

    You're running in a shell script environment, not native windows command prompt.

    0 讨论(0)
  • 2020-12-02 07:12

    Here's mine (in %userprofile%\.gitconfig, or ~/.gitconfig on *nix), no wrapper (Win 7 Home Pro):

    [diff]
        tool = winmerge
    [difftool "winmerge"]
        cmd = c:/path/to/winmergeu.exe -e -u -x -wl -wr -dl "base" -dr "mine" \"$LOCAL\" \"$REMOTE\"
    
    0 讨论(0)
  • 2020-12-02 07:12

    I originally upvoted @CapinWinky's answer for using WinMerge from SourceTree. That answer is still valid, but WinMerge now also supports a three-way merge which needs additional parameters.

    Within the SourceTree Options dialog I chose "Custom" as the Merge Tool, entered the command as:

    C:\Program Files\WinMerge\WinMergeU.exe
    

    and the Arguments as:

    -u -fm -wl -wr -dl Remote_RO -dm Local_Merged -dr Base_RO $REMOTE $LOCAL $BASE -o $MERGED
    

    It doesn't seem to be necessary to enclose the remote/local/base parameters in quotes to cater for paths with spaces in them any more.

    This configuration is for using the middle pane as the merged output file.

    Command line reference

    I had the problem that when trying to merge, WinMerge wouldn't open. Sourcetree starts Git to open your tool of choice. When using Sourcetree's custom option, your git config file (e.g. C:\Users\Me\.gitconfig) is modified to add a new Merge tool called "sourcetree" and the Git command includes --tool=sourcetree . At some point the .gitconfig file hadn't been updated correctly and I had two 'cmd' lines in that section, one being broken:

    [mergetool "sourcetree"]
        cmd = 'C:/Program Files/WinMerge/WinMergeU.exe' -u -fm -wl -wr -dl Remote_RO -dm Local_Merged -dr Base_RO $REMOTE $LOCAL $BASE -o $MERGED
        trustExitCode = true
        cmd = 'C:/Program '
    

    Manually fixing up the .gitconfig file sorted the problem.

    0 讨论(0)
  • If you decide to use SourceTree (or for any Google searchers with SourceTree), you can use WinMerge for the Merge Tool by setting the Merge Tool to custom, pointing Diff Command to WinMergeU.exe, typically:

    C:\Program Files (x86)\WinMerge\WinMergeU.exe
    

    In Arguments use:

    -e -u -dl "Mine" -wr -dr "Theirs" $LOCAL $REMOTE $MERGED
    

    That will cause the left side (labeled "Mine") to be editable and it will be the output file when you save in WinMerge. The right side (labeled "Theirs") will be read only (that's the -wr argument), this is needed because WinMerge outputs all saved files to the $MERGED file, so if both sides were edited, it would output the left side then overwrite that with the right side; best to avoid that kind of confusion.

    If you leave the backup file option turned on, WinMerge will generate a .bak file. The contents of this file will either be the original left side file, or the second to last output file if you saved multiple times. You can either turn this off, or add *.bak to your .gitignore file.

    Git itself will create a *.orig conflict file AFTER the conflict is resolved, just in case you botched it. Again, you can add *.orig to your .gitignore file or turn off this feature. Unfortunately, SourceTree does not have a GUI option for this, so fire up your git bash or, if you chose the right PATH option during installation, the Windows Command prompt and do this:

    git config --global mergetool.keepBackup false
    

    That will stop Git creating the *.orig files. You can also directly edit the config file by locating the .gitconfig file in the root of your user directory. If you know how to use VIM, you can edit the whole thing with this command:

    git config --global --edit
    
    0 讨论(0)
提交回复
热议问题