How to make “git diff” output normal diff format (non-unified, non-context)?

扶醉桌前 提交于 2019-11-29 06:58:58

问题


I want git diff to output normal, plain old diff output (not unified diff, and not context diff).

I want this:

$ diff file1 file2
2c2
< b
---
> B
4d3
< d
5a5
> f

I do NOT want unified output:

$ diff -u file1 file2
--- file1       2012-07-04 07:57:48.000000000 -0700
+++ file2       2012-07-04 07:58:00.000000000 -0700
@@ -1,5 +1,5 @@
 a
-b
+B
 c
-d
 e
+f

I do NOT want context output:

$ diff -c file1 file2
*** file1       2012-07-04 07:57:48.000000000 -0700
--- file2       2012-07-04 07:58:00.000000000 -0700
***************
*** 1,5 ****
  a
! b
  c
- d
  e
--- 1,5 ----
  a
! B
  c
  e
+ f

I tried the various git difftool --tool= args with no luck, and I didn't find anything relevant in git diff --help


回答1:


git difftool --extcmd=diff

or, without prompting:

git difftool --extcmd=diff --no-prompt

This is git difftool rather than git diff but it is doing what I want.




回答2:


You can use same script (see man git(1) for details):

$ cat diff.sh
#!/bin/sh
# get args: path old-file old-hex old-mode new-file new-hex new-mode

diff "$2" "$5"

return=$?
if [ $return -le 1 ]; then
    exit 0
else
    exit $return
fi

$ GIT_EXTERNAL_DIFF=./diff.sh git diff HEAD^..HEAD


来源:https://stackoverflow.com/questions/11331582/how-to-make-git-diff-output-normal-diff-format-non-unified-non-context

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!