配置git DiffMerge工具

git的命令行貌似没有特别好用的UI工具,不管是Android Studio自带的还是其他的,完全代替命令行好像做不到。再加上对git来说没什么比diff和merge更正常不过的事情了。那就配置命令行吧。

Git鼓励在工作流程中频繁使用分支与合并,哪怕一天之内进行许多次都没有关系。理解分支的概念并熟练运用后,你才会意识到为什么Git是一个如此强大而独特的工具,并从此真正改变你的开发方式。” 不是我说的,但是很贴切。

我用的工具是 DiffMerge,比较轻,官网是:http://www.sourcegear.com/diffmerge/

安装在 c 盘之后,需要在git里面配置下,DiffMerge_4.2.0.697.stable_x64 .msi,其中exe为C:Program FilesSourceGearCommonDiffMergesgdm.exe。

具体流程

1.安装DiffMerge

2.配置sgdm.exe路径C:Program FilesSourceGearCommonDiffMerge到windows环境变量的path下

3.配置git

git config --global diff.tool sgdm
git config --global difftool.diffmerge.cmd 'sgdm "$LOCAL" "$REMOTE"'
git config --global merge.tool sgdm
git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'
git config --global mergetool.diffmerge.trustExitCode true

4.用DiffMerge

在代码处理MERGING状态时,可以用命令 git mergetool 启动工具

补:

问题1:

工具会生成.orig文件,可以设置下,让git不再生成:

git config --global mergetool.keepBackup false

问题2:

$ git mergetool
git config option merge.tool set to unknown tool: sgdm
Resetting to default...

This message is displayed because 'merge.tool' is not configured.
See 'git mergetool --tool-help' or 'git help config' for more details.
'git mergetool' will now attempt to use one of the following tools:
tortoisemerge emerge vimdiff
No files need merging

  按照提示,说明git有对merge工具做校验

13051041@CNHQ-13051041N MINGW64 /d/gittest/Test (temp|MERGING)
$ git mergetool --tool-help
'git mergetool --tool=<tool>' may be set to one of the following:
                tortoisemerge
                vimdiff
                vimdiff2
                vimdiff3

        user-defined:
                diffmerge.cmd diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"

The following tools are valid, but not currently available:
                araxis
                bc
                bc3
                codecompare
                deltawalker
                diffmerge
                diffuse
                ecmerge
                emerge
                gvimdiff
                gvimdiff2
                gvimdiff3
                kdiff3
                meld
                opendiff
                p4merge
                tkdiff
                winmerge
                xxdiff

Some of the tools listed above only work in a windowed
environment. If run in a terminal-only session, they will fail.

  我的解决方案是吧sgdm.exe文件复制一份,名字改成diffmerge.exe。还是放在他原来的文件夹下。

修改后,设置脚本所下所示:

git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd 'sgdm "$LOCAL" "$REMOTE"'
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'
git config --global mergetool.diffmerge.trustExitCode true
git config --global mergetool.keepBackup false

  

原文地址:https://www.cnblogs.com/chenjie0949/p/4995566.html