如何使git-diff创建一个“上下文”?格式差异? [英] How to make git-diff create a "context" format diff?

查看:116
本文介绍了如何使git-diff创建一个“上下文”?格式差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Git存储库,除了默认的 git diff 格式。我的用例是,我有一台笨拙的旧OSF / 1计算机,需要在其上应用补丁,而其中的 / bin / patch 程序不理解统一

I've got a Git repo from which I need to create a patch file in something other than the default git diff format. My use case is I've got a clunky old OSF/1 machine on which I need to apply the patch, and the /bin/patch program there doesn't understand unified diffs.

如果我使用 GIT_EXTERNAL_DIFF = diff ,希望以后可以使用 GIT_DIFF_OPTS = -c 请求上下文格式差异,然后我的(现代) diff 程序在命令行上抱怨了额外的参数:

If I use GIT_EXTERNAL_DIFF=diff, hoping that I can then use GIT_DIFF_OPTS=-c to request a context format diff, then my (modern) diff program complains about extra arguments on its command line:

diff: extra operand `373e5907b789a1398a91f4ceb4ab14e8a0ed4282'
diff: Try `diff --help' for more information.
external diff died, stopping at [filename].

设置 GIT_EXTERNAL_DIFF = echo 显示Git似乎使用以下命令运行外部差异程序:

Setting GIT_EXTERNAL_DIFF=echo shows that Git seems to run the external diff program with:

$GIT_EXTERNAL_DIFF <file2> <file1> <hash> <mode> <tmpfilename> <hash> <mode>

这会混淆 diff 额外的参数。有没有一种简单的方法告诉 git diff 创建旧的上下文格式的diff?

This confuses diff which doesn't want the extra arguments. Is there an easy way to tell git diff to create an old-style "context" format diff?

(我目前的计划是编写一个单线shell脚本,该脚本只用 $ 1 $ 2 调用真正的 diff ,但是我'希望有一种比较别扭的方法。)

(My current plan is to write a one-liner shell script that calls the real diff with just $1 $2, but I'm hoping there is a less awkward way.)

推荐答案

配置difftool来完成您想要的事情:

Configure a difftool to do what you want:

$ git config difftool.ctxdiff.cmd 'diff $LOCAL $REMOTE'
$ git difftool -y -t ctxdiff HEAD~4..HEAD

这篇关于如何使git-diff创建一个“上下文”?格式差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆