git添加比较和合并工具(meld)
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)的更多相关文章
- Windows平台下使用Beyond Compare作为GIT默认的比对与合并工具
在Windows平台使用GUI习惯了,因此在CMD命令下反而感到不适 特别是在使用GIT时,尤其明显(这主要是GIT在工作中已经不可或缺) 使用GIT最常用的功能就是提交,添加,比较差异和合并分支,特 ...
- Ubuntu 下安装使用文件比较合并图形工具Meld
Meld是一款跨平台的文件比较合并工具使用Python开发,具体内容参照官网:http://meldmerge.org/ 注意以下环境要求: Requirements Python 2.7 (Pyth ...
- git 分支建立及合并
分支的新建与合并 让我们来看一个简单的分支新建与分支合并的例子,实际工作中你可能会用到类似的工作流. 你将经历如下步骤: 开发某个网站. 为实现某个新的需求,创建一个分支. 在这个分支上开展工作. 正 ...
- ubuntu安装文件比较工具Meld
Meld是一款可视化的文件及目录对比(diff) / 合并 (merge) 工具,通过它你可以对两个或三个文件/目录进行对比,并以图形化的方式显示出它们的不同之处,同时还提供编辑及合并功能,另外还支持 ...
- git 添加外部项目地址
github 提交第三方模块流程 // git config --global user.name 'your name' 可以设置全局用户名,在commit记录里显示的是这个配置设置的名称. / ...
- 文件合并工具DiffMerge发布4.2版本
DiffMerge一直是文件对比合并工具的佼佼者,其最大特点是多文件对比与合并,并提供可视化界面用于编辑. 此次DiffMerge v4.2发布,提高了文件差异对比,并提供了快速匹配功能,以及更好的用 ...
- Git添加远程库和从远程库中获取(新手傻瓜式教学)
一. Git添加远程库 1.在本地新建一个文件夹,在该文件夹使用Git工具,运行$ git init,将该文件夹变为本地Git仓库,同时会生成一个隐藏的.git文件夹. 2.在该文件夹中用Not ...
- Git添加远程库和从远程库中获取
一. Git添加远程库 1. 在本地新建一个文件夹,在该文件夹使用Git工具,运行$ git init,将该文件夹变为本地Git仓库,同时会生成一个隐藏的.git文件夹. 2. 在该文件夹中用Note ...
- Git分支创建与合并
分支管理是Git支持多人协作和版本控制的关键,参照廖雪峰对Git的介绍,对真实开发环境中Git的使用结合实践进行梳理. 摘自:廖雪峰的官方网站 在实际开发中,我们应该按照几个基本原则进行分支管理: 首 ...
随机推荐
- 全平台轻量级 Verilog 编译器 & 仿真环境
一直苦于 modelsim 没有Mac版本,且其体量过大,在学习verilog 时不方便使用. 终于找到一组轻量级且全平台 ( Linux+Windows+macOS ) 的编译仿真工具组. Icar ...
- test文件伪装
该文件属于伪装图片类型.图片另存后把后缀改为rar将看到txt文件. 利用了 cmd cp /b 命令 命令格式:copy /b 文件1+文件2+......文件N 合并后的文件名<br&g ...
- 转:面向切面编程AOP的理解
AOP AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编程)的补充和完善.OOP引入 ...
- 九度OJ 1016 火星A+B AC版
#include <iostream> #include <string.h> #include <sstream> #include <math.h> ...
- 团队作业10——beta阶段项目复审
小组的名字和链接 优点 缺点(bug报告) 最终名次 拖鞋大队 基本功能都实现了,符合用户的需求:每次都能按时完成博客,满足题目要求,所以作业完成的也比较优秀.较alpha版本新增了查重自定义的功能, ...
- 201521123028 《Java程序设计》第6周学习总结
1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 2. 书面作业 Q1.clone方法 1.1 Object ...
- 201521123112《Java程序设计》第5周学习总结
1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点 1.2 可选:使用常规方法总结其他上课内容 课上讲了一些Markdown的用法,包括分割线.参考链接.代码引入等等. 2. 书面 ...
- 201521123045 《Java程序设计》第2周学习总结
---恢复内容开始--- #1. 本周学习总结 上课讲解了上次的实验题目,对其中题目的一些问题得到了解决.学会了java数组的使用,对如何使用码云上传代码有了更清晰的理解.pta还是有一些问题没有解决 ...
- 《JAVA程序设计》第12周学习总结
1. 本章学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. InputStream和OutputStream为所有字节流的父类 通过操作流中的字节可处理各种不同类型的数据 ...
- java课程设计-表达式运算(团队博客)
1 团队课程设计博客 1 团队名称.团队成员介绍 团队名称 奔跑吧土拨鼠 团队成员 洪亚文 201521123065 网络1513 郑晓丽 201521123066 网络1513 2 项目git地址 ...