Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

diff

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

like image 299
Rob Bednark Avatar asked Jul 04 '12 15:07

Rob Bednark


People also ask

What is the output of git diff?

Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

What does ++ mean in git diff?

When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.

How do I get git diff?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch. Order does matter when you're comparing branches.

Why is git diff not showing?

There is no output to git diff because Git doesn't see any changes inside your repository, only files outside the repository, which it considers 'untracked' and so ignores when generating a diff.


2 Answers

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.

like image 112
Rob Bednark Avatar answered Oct 11 '22 08:10

Rob Bednark


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
like image 33
anton0xf Avatar answered Oct 11 '22 09:10

anton0xf