macOS中使用meld作为git mergetool和difftool

来源:互联网 发布:h3c 多个端口删除vlan 编辑:程序博客网 时间:2024/06/16 05:41

本文介绍通过下载meld应用的方式进行配置的过程,不适用于命令行安装的形式。
(命令行安装:brew install caskroom/cask/meld,之后自行尝试…)

meld for OSX:3.16.0
git:2.11.0


mergetool的选择

参考下文:
https://www.slant.co/topics/1324/~diff-tools-for-git

meld截图:
meld


meld下载

meld官方不支持OSX,不过有第三方支持了
https://yousseb.github.io/meld/


meld配置

vi ~/.gitconfig
添加如下内容(确保原来不存在相同项)

[diff]  tool = meld[difftool]  prompt = false[difftool "meld"]  trustExitCode = true  cmd = open -W -a Meld --args \"$LOCAL\" \"$PWD/$REMOTE\"[merge]  tool = meld[mergetool]  prompt = false[mergetool "meld"]  trustExitCode = true  cmd = open -W -a Meld --args --auto-merge \"$PWD/$LOCAL\" \"$PWD/$BASE\" \"$PWD/$REMOTE\" --output=\"$PWD/$MERGED\"

可将上面最后一行中第二个参数 $BASE 改成 $MERGED,弄不清还是别改。

它们之间的差别:

$LOCAL is the file in the current branch .

$REMOTE is the file in the branch being merged .

$MERGED is the partially merged file with the merge conflict information in it.

$BASE is the shared commit ancestor of $LOCAL and $REMOTE.


meld使用

之后当冲突发生时,可以使用
git mergetool
来自动调用meld了

meld的操作非常简单,点点点之后save,然后关掉就可以了。

git difftool

git diff
用法相同
(我遇到了直接使用git difftool不会调用外部工具而使用git diff的情况,后来自己好了..)

不过合并完的时候会发现多了一个untracked文件 *.orig,这是mergetool自动产生的备份文件,保存了合并前的冲突状态下的文件。

如果想禁止自动备份,可以使用
git config --global mergetool.keepBackup false
或者在~/.gitconfig中的[mergetool]下添加
keepBackup = false
效果一样。

如果在meld中不想合并了,可以close without saving,然后git会问你
Was the merge successful? [y/n]
选择n,文件仍会保持冲突状态
选择y,文件会变成合并完成状态

如果文件已经是合并完成状态,又后悔了,那么可以使用自动备份的*.orig来恢复成冲突状态

如果想放弃整次合并,回到pull之前的状态,可以使用
git merge --abort

顺带一提,
.gitconfig中使用#可以注释该行


参考文章

http://stackoverflow.com/questions/34119866/setting-up-and-using-meld-as-your-git-difftool-and-mergetool/34119867#34119867
http://stackoverflow.com/questions/7711727/avoid-orphaned-orig-files-after-resolving-conflicts-from-a-git-merge

0 0