git 下的(difftool)和(mergetool)是专门提供给使用者用自己的工具进行diff和merge的命令:

# git config --global  diff.tool  meld

# git config --global  merge.tool meld

然后直接使用命令进行两次提交的比较和合并:

# git difftool HEAD HEAD^

缺点:

虽然使用git difftool已经基本满足了我的需要,但还有个小问题:如果我要比较两次提交之间的差异时,difftool只能一个文件一个文件的比较,每次都要提示你是否打开这个文件,然后打开meld进行比较,当你关闭meld后,才会提示下一个差异文件。这样非常浪费效率,下面一个方法直接利用meld的目录比较能力(参考: https://github.com/thenigan/git-diffall):

1.新建diffall文本文件

2.在diffall文件中添加如下代码:

 #!/bin/sh
# Copyright - , Tim Henigan <tim.henigan@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # Perform a directory diff between commits in the repository using
# the external diff or merge tool specified in the user's config. USAGE='[--cached] [--copy-back] [-x|--extcmd=<command>] <commit>{0,2} [-- <path>*]
--cached Compare to the index rather than the working tree.
--copy-back Copy files back to the working tree when the diff
tool exits (in case they were modified by the
user). This option is only valid if the diff
compared with the working tree.
-x=<command>
--extcmd=<command> Specify a custom command for viewing diffs.
git-diffall ignores the configured defaults and
runs $command $LOCAL $REMOTE when this option is
specified. Additionally, $BASE is set in the
environment.
' SUBDIRECTORY_OK=
. "$(git --exec-path)/git-sh-setup" TOOL_MODE=diff
. "$(git --exec-path)/git-mergetool--lib" merge_tool="$(get_merge_tool)"
if test -z "$merge_tool"
then
echo "Error: Either the 'diff.tool' or 'merge.tool' option must be set."
usage
fi start_dir=$(pwd) # All the file paths returned by the diff command are relative to the root
# of the working copy. So if the script is called from a subdirectory, it
# must switch to the root of working copy before trying to use those paths.
cdup=$(git rev-parse --show-cdup) &&
cd "$cdup" || {
echo >& "Cannot chdir to $cdup, the toplevel of the working tree"
exit
} # set up temp dir
tmp=$(perl -e 'use File::Temp qw(tempdir);
$t=tempdir("/tmp/git-diffall.XXXXX") or exit();
print $t') || exit 1
trap 'rm -rf "$tmp"' EXIT left=
right=
paths=
dashdash_seen=
compare_staged=
merge_base=
left_dir=
right_dir=
diff_tool=
copy_back= while test $# !=
do
case "$1" in
-h|--h|--he|--hel|--help)
usage
;;
--cached)
compare_staged=
;;
--copy-back)
copy_back=
;;
-x|--e|--ex|--ext|--extc|--extcm|--extcmd)
if test $# =
then
echo You must specify the tool for use with --extcmd
usage
else
diff_tool=$
shift
fi
;;
--)
dashdash_seen=
;;
-*)
echo Invalid option: "$1"
usage
;;
*)
# could be commit, commit range or path limiter
case "$1" in
*...*)
left=${%...*}
right=${#*...}
merge_base=
;;
*..*)
left=${%..*}
right=${#*..}
;;
*)
if test -n "$dashdash_seen"
then
paths="$paths$1 "
elif test -z "$left"
then
left=$
elif test -z "$right"
then
right=$
else
paths="$paths$1 "
fi
;;
esac
;;
esac
shift
done # Determine the set of files which changed
if test -n "$left" && test -n "$right"
then
left_dir="cmt-$(git rev-parse --short $left)"
right_dir="cmt-$(git rev-parse --short $right)" if test -n "$compare_staged"
then
usage
elif test -n "$merge_base"
then
git diff --name-only "$left"..."$right" -- $paths >"$tmp/filelist"
else
git diff --name-only "$left" "$right" -- $paths >"$tmp/filelist"
fi
elif test -n "$left"
then
left_dir="cmt-$(git rev-parse --short $left)" if test -n "$compare_staged"
then
right_dir="staged"
git diff --name-only --cached "$left" -- $paths >"$tmp/filelist"
else
right_dir="working_tree"
git diff --name-only "$left" -- $paths >"$tmp/filelist"
fi
else
left_dir="HEAD" if test -n "$compare_staged"
then
right_dir="staged"
git diff --name-only --cached -- $paths >"$tmp/filelist"
else
right_dir="working_tree"
git diff --name-only -- $paths >"$tmp/filelist"
fi
fi # Exit immediately if there are no diffs
if test ! -s "$tmp/filelist"
then
exit
fi if test -n "$copy_back" && test "$right_dir" != "working_tree"
then
echo "--copy-back is only valid when diff includes the working tree."
exit
fi # Create the named tmp directories that will hold the files to be compared
mkdir -p "$tmp/$left_dir" "$tmp/$right_dir" # Populate the tmp/right_dir directory with the files to be compared
while read name
do
if test -n "$right"
then
ls_list=$(git ls-tree $right "$name")
if test -n "$ls_list"
then
mkdir -p "$tmp/$right_dir/$(dirname "$name")"
git show "$right":"$name" >"$tmp/$right_dir/$name" || true
fi
elif test -n "$compare_staged"
then
ls_list=$(git ls-files -- "$name")
if test -n "$ls_list"
then
mkdir -p "$tmp/$right_dir/$(dirname "$name")"
git show :"$name" >"$tmp/$right_dir/$name"
fi
else
if test -e "$name"
then
mkdir -p "$tmp/$right_dir/$(dirname "$name")"
cp "$name" "$tmp/$right_dir/$name"
fi
fi
done < "$tmp/filelist" # Populate the tmp/left_dir directory with the files to be compared
while read name
do
if test -n "$left"
then
ls_list=$(git ls-tree $left "$name")
if test -n "$ls_list"
then
mkdir -p "$tmp/$left_dir/$(dirname "$name")"
git show "$left":"$name" >"$tmp/$left_dir/$name" || true
fi
else
if test -n "$compare_staged"
then
ls_list=$(git ls-tree HEAD "$name")
if test -n "$ls_list"
then
mkdir -p "$tmp/$left_dir/$(dirname "$name")"
git show HEAD:"$name" >"$tmp/$left_dir/$name"
fi
else
mkdir -p "$tmp/$left_dir/$(dirname "$name")"
git show :"$name" >"$tmp/$left_dir/$name"
fi
fi
done < "$tmp/filelist" LOCAL="$tmp/$left_dir"
REMOTE="$tmp/$right_dir" if test -n "$diff_tool"
then
export BASE
eval $diff_tool '"$LOCAL"' '"$REMOTE"'
else
run_merge_tool "$merge_tool" false
fi # Copy files back to the working dir, if requested
if test -n "$copy_back" && test "$right_dir" = "working_tree"
then
cd "$start_dir"
git_top_dir=$(git rev-parse --show-toplevel)
find "$tmp/$right_dir" -type f |
while read file
do
cp "$file" "$git_top_dir/${file#$tmp/$right_dir/}"
done
fi

3.保存,运行如下命令配置

# git config --global alias.diffall /PATH/diffall
												

git添加比较和合并工具(meld)的更多相关文章

  1. Windows平台下使用Beyond Compare作为GIT默认的比对与合并工具

    在Windows平台使用GUI习惯了,因此在CMD命令下反而感到不适 特别是在使用GIT时,尤其明显(这主要是GIT在工作中已经不可或缺) 使用GIT最常用的功能就是提交,添加,比较差异和合并分支,特 ...

  2. Ubuntu 下安装使用文件比较合并图形工具Meld

    Meld是一款跨平台的文件比较合并工具使用Python开发,具体内容参照官网:http://meldmerge.org/ 注意以下环境要求: Requirements Python 2.7 (Pyth ...

  3. git 分支建立及合并

    分支的新建与合并 让我们来看一个简单的分支新建与分支合并的例子,实际工作中你可能会用到类似的工作流. 你将经历如下步骤: 开发某个网站. 为实现某个新的需求,创建一个分支. 在这个分支上开展工作. 正 ...

  4. ubuntu安装文件比较工具Meld

    Meld是一款可视化的文件及目录对比(diff) / 合并 (merge) 工具,通过它你可以对两个或三个文件/目录进行对比,并以图形化的方式显示出它们的不同之处,同时还提供编辑及合并功能,另外还支持 ...

  5. git 添加外部项目地址

    github 提交第三方模块流程   // git config --global user.name 'your name' 可以设置全局用户名,在commit记录里显示的是这个配置设置的名称. / ...

  6. 文件合并工具DiffMerge发布4.2版本

    DiffMerge一直是文件对比合并工具的佼佼者,其最大特点是多文件对比与合并,并提供可视化界面用于编辑. 此次DiffMerge v4.2发布,提高了文件差异对比,并提供了快速匹配功能,以及更好的用 ...

  7. Git添加远程库和从远程库中获取(新手傻瓜式教学)

    一.    Git添加远程库 1.在本地新建一个文件夹,在该文件夹使用Git工具,运行$ git init,将该文件夹变为本地Git仓库,同时会生成一个隐藏的.git文件夹. 2.在该文件夹中用Not ...

  8. Git添加远程库和从远程库中获取

    一. Git添加远程库 1. 在本地新建一个文件夹,在该文件夹使用Git工具,运行$ git init,将该文件夹变为本地Git仓库,同时会生成一个隐藏的.git文件夹. 2. 在该文件夹中用Note ...

  9. Git分支创建与合并

    分支管理是Git支持多人协作和版本控制的关键,参照廖雪峰对Git的介绍,对真实开发环境中Git的使用结合实践进行梳理. 摘自:廖雪峰的官方网站 在实际开发中,我们应该按照几个基本原则进行分支管理: 首 ...

随机推荐

  1. h5audio标签

    因为音频格式有版权,各浏览器使用不同的音频格式. 音频格式兼容性 音频格式 Chrome Firefox IE9 Opera Safari MP3 支持 不支持 支持 不支持 支持 OGG 支持 支持 ...

  2. 前端开发【第4篇:JavaScript基础】

    JavaScript简述 上一篇文章已经聊过JavaScript的历史了这里不再复述了直接切入正题,JavaScript是一门解释型.动态类型.弱类型语言. 解释型语言和编译型语言就类似看一本书,编译 ...

  3. JS中window.showModalDialog()详解(转)

    window.showModalDialog()方法用来创建一个显示HTML内容的模态对话框. window.showModelessDialog()方法用来创建一个显示HTML内容的非模态对话框.  ...

  4. Java基础学习 —— 线程

    线程: 多线程的好处:解决了在一个进程中同时执行多个任务代码的问题. 自定义线程的创建方式: 1.自定一个类继承thread类,重写thread的run方法 吧自定义线程的任务代码写在run方法内,创 ...

  5. CentOS 7 更改网卡名为eth0

    今天用VBOX安装了CentOS7, 但是安装完之后,发现没有ifconfig命令,在网上搜了一下解决办法,在可以连网状态下,输入下面命令即可 然后就可以用ifconfig命令了. 使用ifconfi ...

  6. poj 1948二维01背包

    题意:给出不多于40个小棍的长度,求出用所有小棍组成的三角形的最大面积. 思路:三角形3边求面积,海伦公式:p=(a+b+c)/2;S=p*(p-a)*(p-b)*(p-c);因为最大周长为1600  ...

  7. eclipse+git

    最近朋友都推荐使用github管理自己的项目,而且免费用户可以有5个仓库,恰好我也想了解下git,借此机会学习一下.github官方指南使用独立第三方git工具来进行版本控制,并不借助于eclipse ...

  8. 转:swagger 入门

    前言 swagger ui是一个API在线文档生成和测试的利器,目前发现最好用的. 为什么好用?Demo 传送门 支持API自动生成同步的在线文档 这些文档可用于项目内部API审核 方便测试人员了解A ...

  9. 201521123088《java程序设计》第四次总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.11.2 使用常规方法总结其他上课内容 1.多态:同一操作作用于不同的对象,可以有不同的解释,产生不同的执行结果,这就是多态性. ...

  10. 201521123096《Java程序设计》第三周学习总结

    1. 本周学习总结 2. 书面作业 (1)代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; ...