Windows下使用Beyond Compare作为git的比对与合并工具



Windows下使用Beyond Compare作为git的比对与合并工具

Windows下使用Beyond Compare作为git的比对与合并工具

介绍

其实各种git的GUI客户端都有自带比对工具,但是一开始学Git的时候,用的是Windows下的Git Bash,后来也渐渐熟悉各种命令,用图形客户端反而不习惯了。 这里介绍如何将Beyond Compare配置为git的difftool和mergetool。当需要比对或者合并冲突时,就可以通过difftool和mergetool调用Beyond Compare进行比对和合并冲突了。

操作

目前我电脑里安装的是Beyond Compare 4,就介绍一下4的设置,Beyond Compare 3也是类似的。
其实Beyond Compare官网就有介绍 如何配置git的difftool和mergetool,其实就几行git命令。

#difftool 配置
git config --global diff.tool bc4
git config --global difftool.bc4.cmd "\"c:/program files (x86)/beyond compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\""

#mergeftool 配置
git config --global merge.tool bc4
git config --global mergetool.bc4.cmd "\"c:/program files (x86)/beyond compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\""
git config --global mergetool.bc4.trustExitCode true

但是我照着上面的步骤配置,使用difftool命令后,发现左右两边都为空白文件。研究了半天没研究出个所以然。 后来突然想起来用户目录下的.gitconfig看看配置情况,才发现原因。 打开配置文件看到的信息差不多是这样:

[diff]
tool = bc4
[difftool]
prompt = false
[difftool "bc4"]
cmd = \"c:/program files (x86)/beyond compare 4/bcomp.exe\" 

.....

使用git bash是执行上述几个命令后,.gitconfig文件中并没有 \"$LOCAL\" \"$REMOTE\""的影子,所以使用difftool比对文件时,两边都是空白,因为根本就没有传参数进去。 所以换一个思路,不用命令设置,而是直接编辑.gitconfig文件设置,就没问题了。

.gitconfig文件新增如下配置并保存

[diff]
tool = bc4
[difftool]
prompt = false
[difftool "bc4"]
cmd = "\"c:/program files (x86)/beyond compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\""
[merge]
tool = bc
[mergetool]
prompt = false
[mergetool "bc4"]
cmd = "\"c:/program files (x86)/beyond compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\""

然后在git命令行中执行相关命令就ok啦:)

#比对当前文件相对于Head版本的改动
git difftool <file_name>

#当merge <branch_name>提示冲突时,执行下面命令便可以调出bc合并冲突
git mergetool


http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/
http://www.open-open.com/lib/view/open1332904495999.html
http://www.csdn.net/article/2013-08-22/2816665-10-useful-advanced-git-commands
http://blog.csdn.net/cailiwei712/article/details/7469018

http://sfault-image.b0.upaiyun.com/37/92/37923f2478edc5709b36562b26c9e008

http://blog.chinaunix.net/uid-13344516-id-4486211.html
http://git-scm.com/book/zh/v1/Git-基础-记录每次更新到仓库
http://os.51cto.com/art/201312/425331.htm



笨办法:

  1. 首先,保证你的本地repo处于最新状态(该提交的提交了,该pull都pull好了,等等)

  2. 用git reflog找到对应的commit

  3. 用git reset --hard head@{id}回退到指定的commit

  4. 复制需要的文件

  5. 用git pull origin master回到最新的状态




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值