如何用msysgit / gitk设置DiffMerge? [英] How do I setup DiffMerge with msysgit / gitk?

查看:205
本文介绍了如何用msysgit / gitk设置DiffMerge?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用Git,可能我错过了一些明显的东西,但是这里有:


  • 我正在使用在Windows XP上安装msysgit 1.6.2.2

  • 在安装时,我选择了选项1仅限使用Git Bash


    我试图把一个包装脚本放在一起,我可以用它来用DiffMerge代替内置的git diff。基于在评论中添加了内容:


    添加了' / bin / sh '标题并尝试再次运行git diff。

    这次错误是:

    意外的参数'C:/Docume~/avggeek/LOCALS~1/Temp/.diff_b08444

    有没有办法看到什么是当我调用 git diff


    1 /一种方法来查看通过什么参数!

    C:\ Program Files \Git\libexec\git-core\\中添加以下行git-sh-setup file:

      git_editor(){
    :$ { GIT_EDITOR:= $(git config core.editor)}
    :$ {GIT_EDITOR:= $ {VISUAL: - $ {EDITOR}}}
    case $ GIT_EDITOR,$ TERMin
    ,dumb)
    echo>& 2没有在GIT_EDITOR,core.editor,VISUAL,
    echo& 2或EDITOR中指定编辑器。
    echo>& 2请将其中一个变量设置为合适的
    echo& 2编辑器,或运行$ 0的选项这将不会导致调用
    echo& 2编辑器(例如,-m或-F用于git-commit)。
    exit 1
    ;;
    esac
    ####在下面添加以下行
    echo>& 2editor is $ {GIT_EDITOR:= vi} $ @。
    #### END ADD ADDITIONAL above
    eval$ {GIT_EDITOR:= vi}'$ @'
    }

    您将看到正在调用哪个编辑器,并带有什么参数。

    现在,关于Unexpected parameter部分:

    I当我使用 / e / ub >而不是 -e -ub ,所以第一个问题是:

    您确定 / title1 位不能用作 -title1 -t1 - title1 - -t1 ?这是从第9章Command行参数的DiffMerge的PDF文档
    如果不是,我怀疑一些双引号是为了正确分隔不同的参数。例如:

     / title1 =旧版本$ 2/ title2 =新版本$ 5 

    / title1 = \旧版本\$ 2/ title2 = \新版本\$ 5

    但我的钱宁愿放在 -title1 -t1 form:

      -t1 =旧版本$ 2 -t2 =新版本$ 5

    应该可以正常工作。


    I've just started using Git and it's possible I've missed something obvious, but here goes:

    • I'm using msysgit 1.6.2.2 on Windows XP
    • While installing, I picked option 1 to "Use Git Bash only"

    I'm trying to put together a wrapper script that I can use to replace the built in git diff with DiffMerge. Based on this thread on SO, I created the following batch file:

    @echo off
    REM ---- Switch forward slashes to back slashes ----
    set oldW=%2
    set oldW=%oldW:/=\%
    set newW=%5
    set newW=%newW:/=\%
    
    REM ---- Launch DiffMerge ----
    "C:/Programs/SourceGear/DiffMerge/DiffMerge.exe" /title1="Old Version" %oldW% /title2="New Version" %newW%
    

    I placed the bat file under %GIT_INSTALL%/cmd and edited my .gitconfig file as follows:

    [diff]
    external = C:/Programs/git/cmd/git-diff-wrapper.bat
    

    If i launch Git Bash and execute git diff HEAD HEAD~ -- myfile

    I get a message File (\dev\null) not found - which given I'm on Windows is not surprising.

    Pressing on, I launched gitk and under Edit>Preferences, I chose the same wrapper script. Trying the "external diff" option for a particular file gives the cryptic error message Unknown Option "

    Clearly, I have no idea what I'm doing anymore so any help would be much appreciated.

    解决方案

    I just experienced a somewhat similar experience with setting Notepad++ as my external editor with msysgit1.6.2.2.

    The key was to realize the wrapper was not a DOS script, but a /bin/sh script.

    So try to put in your ".bat" (even though it is not exactly a bat script, the extension is not important here):

    #!/bin/sh
    
    # diff is called by git with 7 parameters:
    # path old-file old-hex old-mode new-file new-hex new-mode
    
    "C:/Programs/SourceGear/DiffMerge/DiffMerge.exe" /title1="Old Version" "$2" /title2="New Version" "$5" | cat
    

    Do not worry about making all the '\' go '/': it is done by the Git scripts calling the external diff tool.

    I did not test it with DiffMerge, but with WinMerge, it works just fine, both from a DOS session or a Git Shell.

    #!/bin/sh
    "C:/Program Files/WinMerge/WinMergeU.exe" -e -ub "$2" "$5" | cat
    

    (with the '-e' option, I have just ot type on 'ESC' to close and quit the diff tool: that works great!)


    average_geek adds in the comments:

    added the '/bin/sh' header and tried running git diff again.
    This time the error is:
    Unexpected parameter 'C:/Docume~/avggeek/LOCALS~1/Temp/.diff_b08444
    Is there a way to see what are the parameters getting passed when I call git diff ?

    1/ There actually is a way to see what are the parameters getting passed!
    Add the following line in the C:\Program Files\Git\libexec\git-core\git-sh-setup file:

    git_editor() {
        : "${GIT_EDITOR:=$(git config core.editor)}"
        : "${GIT_EDITOR:=${VISUAL:-${EDITOR}}}"
        case "$GIT_EDITOR,$TERM" in
        ,dumb)
            echo >&2 "No editor specified in GIT_EDITOR, core.editor, VISUAL,"
            echo >&2 "or EDITOR. Tried to fall back to vi but terminal is dumb."
            echo >&2 "Please set one of these variables to an appropriate"
            echo >&2 "editor or run $0 with options that will not cause an"
            echo >&2 "editor to be invoked (e.g., -m or -F for git-commit)."
            exit 1
            ;;
        esac
    #### ADD THIS LINE BELOW
        echo >&2 "editor is ${GIT_EDITOR:=vi} $@."
    #### END ADDITION ABOVE
        eval "${GIT_EDITOR:=vi}" '"$@"'
    }
    

    You will see what editor is being called, with what parameter.

    Now, regarding the "Unexpected parameter" part:
    I did have the same kind of error when I called WinMergeU.exe with "/e /ub" instead of "-e -ub", so first question is:
    Are you sure that the "/title1" bit could not be used as "-title1" or "-t1" or "--title1" or "--t1" ? That is what Is can see from the chapter 9 "Command Lines Arguments" of the pdf documentation of DiffMerge.
    If not, I suspect some double quotes are in order for delimiting properly the different parameters. Something like:

    "/title1="Old Version"" "$2" "/title2="New Version"" "$5"
    or
    "/title1=\"Old Version\"" "$2" "/title2=\"New Version\"" "$5"
    

    But my money would rather be on the "-title1" or "-t1" form:

    -t1="Old Version" "$2" -t2="New Version" "$5"
    

    should work just fine.

    这篇关于如何用msysgit / gitk设置DiffMerge?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆