用Beyond Compare代替git的difftool和mergetool

Note:  If you use the Git for Windows' Bash Command Prompt instead of the default Windows Command Prompt, you need to escape the $ character with \.

For Git 1.7.6 and newer, edit the global config file to set the path:


Diff

At a Windows command prompt enter the commands:
  git config --global diff.tool bc3
  git config --global difftool.bc3.cmd "\"c:/program files/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\""
  git config --global difftool.prompt false

To launch a diff with BC3, use the command "git difftool foofile.txt".

Merge

At a Windows command prompt, enter the commands:
  git config --global merge.tool bc3
  git config --global mergetool.bc3.cmd "\"c:/program files/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\""
  git config --global mergetool.bc3.trustExitCode true

To launch a 3-way merge with BC3, use the command "git mergetool foofile.txt".



diff时,用git difftool <file_name>来查看就会直接弹出bcompare.

merge时,要先用git merge <branch_name> 来merge一下,然后如果提示merge有冲突,才用git mergetool来调用bcompare来merge


再次更新:
可能是msys的bug吧,当我想用difftool去比较不同branch或changeset的相同文件时,bcompare找不到文件。我去它给出的目录确实找不到,这个很奇怪。可能是缓存文件未创建出来或者已经被删除了。
为了证实自己的想法,写了个小shell脚本,把缓存文件拷到另一个地方,这样在我打开的时候就不会被删了吧。
过程如下:
1. 创建shell(名叫:git-bcompare.sh)脚本

#!/bin/sh echo "[File1: ]" $1 echo "[File2: ]" $2 export f_path=$2 export f_path=/c/Users/xyanfxu/temp/${f_path##*/} echo "[Cache: ]" $f_path cp -r $2 /c/Users/xyanfxu/temp start /c/Tools/BC3/BCompare.exe $1 $f_path #trap "rm -r $f_path;exit" 1 2 3 15 sleep 5 rm -r $f_path

这里本来想用trap的,发现不能用……因为start的是外部程序,它捕获不到信号。索性用sleep5秒,再删。反正bcompare只要能打开就可以缓存。右边文件本身就是某branch下的,又不能直接更改。
2. 把sh文件加到git中

chmod 777 ~/git-bcompare.sh

git config --global diff.external ~/git-bcompare.sh

这样用git diff的时候,默认就用bcompare打开了。
结果我尝试用git diff branch1:test.txt branch2:test.txt 去打开时,shell中显示cp命令找不到文件。果然是没创建缓存啊。
可能是git的bug.

然而换一种方式来用:git diff 8831524 e994d87c就可以了。 两个字符串是test.txt的不同changeset里面的hash值。
所以更好的使用方式就是git difftool 8831524 e994d87c

结尾加上一些常用的git命令:
git add <file_name>
git commit
git diff
git difftool
git log --pretty=oneline <file_name> 显示该文件(如果留空就是文件夹)的历史记录
git push 更新到服务器
git pull 拉最新的仓库
git reset 将当前的HEAD指向最初的base,但是当前的文件保留。 如果加上--hard,就是HEAD加文件都完全变成base的
git rebase -i <changeset_hash / branch_name> 是将changeset_hash / branch_name之后的所有commit进行合并操作,第一个commit保留pick,后面的squash
另转一个做的很好的git的介绍slides
写给大家的Git教学
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值