git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Question: Getting 'git diff' to generate /usr/bin/diff output

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 17, 2016, 07:46 UTC
Message-ID
<alpine.DEB.2.20.1607170942580.28832@virtualbox>
In-Reply-To
<578a9d5b.xL1egXSTCv+mjhAT%perryh@pluto.rain.com>
Hi,

[Perry, my mailer could not find your MX record, so I am sorry I had to drop you from the explicit To:...]

On Sat, 16 Jul 2016, Perry Hutchison wrote:
Show 11 quoted lines
> norm@dad.org wrote:
> 
> > Would some kind soul be willing to tell me if there is a way to
> > do that, short of making a backup copy of the relevant file, and
> > then doing 'git checkout'. Maybe the '--ext-diff' argument to
> > 'git diff' will do that, but I can't figure out how to use it.
> > ...
> >     git version: 2.5.1.454.g1616360
> 
> 'git cat' would be simpler than making a backup and using 'git checkout',
> but for this use case there's a better way even than that.

$ git cat git: 'cat' is not a git command. See 'git --help'.

;-)
You probably meant `git cat-file blob <SHA-1>`.
Show 13 quoted lines
> Google is your friend when you can't figure something out from (or
> find the right part of) a program's own documentation.  A search for
> 
>     git "external diff program"
> 
> (including the quotes) found several references.
> 
> One possible complication:  It's likely that the command parameters
> which git passes to an external diff program are not exactly what
> /usr/bin/diff requires.  The solution to that sort of problem is to
> write a very short executable script that rearranges the parameters
> as needed, and specify that script (instead of /usr/bin/diff itself)
> as the external diff program.

To spell it out, you probably referred to the --ext-diff option: https://github.com/git/git/blob/v2.9.2/Documentation/diff-options.txt#L528-L531

This option can be used with any diff-producing Git command, but it requires a .gitattribute setting together with the corresponding diff.external setting in the config.

A better method might be to use the `git difftool` command, e.g.
	git difftool -x diff
You can also inspect the diff of a commit, using the ^! suffix, e.g.
	git difftool -x diff origin/master~3^!

If you want to avoid the prompt and get the complete diff for all files in one go, you will have to write a small script as indicated, e.g.

	printf '#!/bin/sh\n\n/usr/bin/diff -r "$@"\n' >my-diff.sh
	chmod a+x my-diff.sh
	git difftool -d -x $PWD/my-diff.sh HEAD^!

I did write all of this in the mail program, so I highly recommend reading the man page of the difftool e.g. to understand the meaning of the -d option, so that you can fix any problems with my examples yourself.

Ciao, Johannes

Previous: Perry HutchisonNext: norm@dad.org
Message 3 of 12 in “Question: Getting 'git diff' to generate /usr/bin/diff output”
  1. norm@dad.orgJul 16, 2016
  2. Perry HutchisonJul 16, 2016
  3. Johannes SchindelinJul 17, 2016
  4. norm@dad.orgJul 19, 2016
  5. René ScharfeJul 17, 2016
  6. norm@dad.orgJul 17, 2016
  7. Johannes SchindelinJul 18, 2016
  8. pager: disable color when pager is "more"Eric Wong, Jul 18, 2016
  9. Jeff KingJul 18, 2016
  10. Junio C HamanoJul 18, 2016
  11. Jeff KingJul 18, 2016
  12. Eric WongJul 19, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.