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. basepath的作用 (转)

    转自:http://blog.csdn.net/randomnet/article/details/8630754   在谈basePath之前,先来讨论一下相对路径与绝对路径的区别.    相对路径 ...

  2. Thinkphp3.2.3框架下封装公共的函数,例如封装CURL函数来获取接口数据

    当我们需要在控制层调用相同的封装函数时,写多次相同的函数,显得代码十分的拉杂,不精简: TP框架有一个很好的机制,可以再Common定义一个function.php函数,当我们在控制层调用的时候直接调 ...

  3. 查看numpy.ndarray的数据类型

    使用ndarray数据时,如果希望知道数据的类型和维数,可以按照以下方法: Xxx.dtype  #xxx表示一个ndarray类型的变量,返回ndarray的数据类型 Xxx.shape  #xxx ...

  4. 转深入Java虚拟机 之四:类加载机制

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/17881581 类加载过程     类从被加载到虚拟机内存中开始,到卸载出内存为止,它的整个 ...

  5. 结对编程1---基于Flask的四则运算题目生成器

    项目代码地址 / WEB应用地址 / 合作伙伴iFurySt博文链接 需求分析 本次程序是基于原有的控制台四则运算器的基础上,改成WEB的形式,同时还增加了一些新的功能.同时因为交互方式的改变,代码也 ...

  6. 201521123078 《java》第五周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 2. 书面作业 代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过?哪句 ...

  7. 自定义win8资源管理器左侧导航窗格的方法

    Win8自定义资源管理器左侧导航窗格: 快捷键Win+R – 输入regedit: 删除“网络”项目 HKEY_CLASSES_ROOTCLSID{F02C1A0D-BE21-4350-88B0-73 ...

  8. Java课程设计-定时器(团队)

    一.团队介绍(没头脑和不高兴) 陈文俊[组长] 201521123047 网络1512 宣委 郑子熙 201521123045 网络1512 二.项目Git链接 定时器 三.项目git提交记录截图 四 ...

  9. 201521123018 《Java程序设计》第11周学习总结

    1. 本章学习总结 你对于本章知识的学习总结 2. 书面作业 一.互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) 1.1 除了使用synchronized修饰方法实现互斥同步访问, ...

  10. cityEngine入门(实现数据的预处理以及cityEngine的3维显示)

    一.  实验要求 1.     提供数据: 中田村两个图幅影像数据 DEM提供包含高程数值的文本和矢量数数据 完成内容: 实现中田村两个图幅的拼接,生成一个影像数据(Image.tif) 将DEM数据 ...