How can I make WinMerge my git mergetool?

后端 未结 12 1677
既然无缘
既然无缘 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 06:56

    You are talking about merge tool, yet you (and some other people with answers) are configuring it as a diff tool.

    To configure a merge tool, you'd need to use merge.tool and mergetool configurations instead of diff.tool and difftool, like this:

    git config --global merge.tool winmerge
    git config --replace --global mergetool.winmerge.cmd "\"C:\Program Files (x86)\WinMerge\WinMergeU.exe\" -e -u -dl \"Base\" -dr \"Mine\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\""
    git config --global mergetool.prompt false
    

    And then you can use

    git mergetool
    

    which will open you the two files to edit.

    Kudos for @dvdvck mentioning in the comments that in command line parameters you can specify a third file for the result file for winmerge (outputpath parameter).

    For completeness, I'll mention that there is also this gist aimed at full configuration of winmerge for both as diff and merge tool.

    0 讨论(0)
  • 2020-12-02 06:57

    Entering the settings via the command line has been covered by other answers. The .gitconfig file for full 3-way merging with WinMerge could be configured like this (this example is from Windows):

    [merge]
        tool = WinMerge
    
    [mergetool "WinMerge"]
        cmd = \"C:\\Program Files\\WinMerge\\WinMergeU.exe\" -e -u -dl \"Local\" -dm \"Base\" -dr \"Remote\" \"$LOCAL\" \"$BASE\" \"$REMOTE\" -o \"$MERGED\"
        trustExitCode = true
        keepBackup = false
    
    [diff]
        tool = WinMerge
    
    [difftool "WinMerge"]
        cmd = \"C:\\Program Files\\WinMerge\\WinMergeU.exe\" -e -u -dl \"Old $BASE\" -dr \"New $BASE\" \"$LOCAL\" \"$REMOTE\"
        trustExitCode = true
    

    Flag information:

    • /e - Allows WinMerge to be closed via a single press of the 'esc' key.
    • /u - Prevents WinMerge from logging the files in the recently used list.
    • /dl, /dm, and /dl - Descriptions for Left, Middle, and Right panes.
    • /o - The output file. Saving ANY pane will output that pane's contents to the output file.

    trustExitCode = true tells git to accept the output without further prompt.

    keepBackup = false will automatically delete the automatically generated *.orig files.

    Note: The $BASE and $MERGE variables when using difftool both simply contain the filename.

    0 讨论(0)
  • 2020-12-02 06:59

    Git 2.5+ (Q2 2015) will include Winmerge as a known git mergetool!

    If Winmerge is in your %PATH%, a git config merge.tool winmerge is all you need to do!
    (It works for diff tool too: git config diff.tool winmerge)

    See commit 3e4f237 by David Aguilar (davvid), 20 May 2015.
    (Merged by Junio C Hamano -- gitster -- in commit 324a9f4, 01 Jun 2015)
    Helped-by: Philip Oakley (PhilipOakley), Johannes Schindelin (dscho), Sebastian Schuberth (sschuberth), SZEDER Gábor (szeder)

    All the config is now done for you directly in Git itself, with mergetools/winmerge:

    • diff command: "$merge_tool_path" -u -e "$LOCAL" "$REMOTE"
    • merge command: "$merge_tool_path" -u -e -dl Local -dr Remote "$LOCAL" "$REMOTE" "$MERGED"

    mergetools: add winmerge as a builtin tool

    Add a winmerge scriptlet with the commands described in this thread, so that users can use winmerge without needing to perform any additional configuration.

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

    After hassling with this for over an hour, I installed tortoisegit and so far it's giving me exactly what I want.

    Settings of Winmerge for Tortoise git are described in http://thoai-nguyen.blogspot.com.au/2012/03/setup-tortoise-git-and-winmerge.html

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

    After installing TortoiseGit and WinMerge 2.16 (this version supports 3-way merging), I found how WinMerge integrate itself to TortoiseGit:

    D:\Program Files\WinMerge\WinMergeU.exe /e /ub /fm /wl /wr /dl %tname /dm %bname /dr %yname  %theirs %base %mine /o %merged /am
    

    So I edited the .gitconfig file and change some vars to make it work for me (I added WinMerge dir to the system path):

    [mergetool "winmerge"]
        cmd = WinMergeU -e -ub -fm -wl -wr $LOCAL $BASE $REMOTE -o $MERGED -am
    
    0 讨论(0)
  • 2020-12-02 07:05

    Example:

    git config --global --add diff.tool winmerge
    git config --replace --global difftool.winmerge.cmd "\"C:\Program Files (x86)\WinMerge\WinMergeU.exe\" -e -u -dl \"Base\" -dr \"Mine\" $LOCAL $REMOTE"
    git config --global difftool.prompt false
    
    0 讨论(0)
提交回复
热议问题