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

Re: how to create a diff in old file new file format (for code reviews)

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Dec 14, 2010, 09:17 UTC
Message-ID
<4D073619.2010103@drmicha.warpmail.net>
In-Reply-To
<1292285257962-5832810.post@n2.nabble.com>
aerosmith venit, vidit, dixit 14.12.2010 01:07:
Show 10 quoted lines
> 
> Hi,
> 
> I am trying to create a diff such that the original file (entire file) is
> saved something like file1.h.old and the new modified file as file1.h.new. I
> have read the various options for git-diff* tools but could not find one
> such utility. All I get is the removals and additions as a diff. Does anyone
> know how to create one with the help the available git utils? The only
> method that I can think of is to do everything manually. Any help w.r.t.
> this is really appreciated. Thanks in advance.

You could script around this e.g. with an external diff-helper. The easiest way is to reuse difftool. For example,

git difftool -y -x echo <revexpression>

will give you pairs of names of temporary files for old/new, where <revexpression> is what you would give to "git diff" to specify what to diff.

With the patch I'm sending in a minute, the helper you specify with "-x" can also access the basename easily, so that you could use "-x oldnew" with a script "oldnew" containing

#!/bin/sh cp "$1" "$BASE".old cp "$2" "$BASE".new

Even without the patch, you could use

git difftool -y -x 'cp "$LOCAL" "$BASE".old; cp "$REMOTE" "$BASE.new"; #' <revexpression>

(all on one line) directly. But this requires insider knowledge and may break some day.

Cheers, Michael

Previous: aerosmithNext: Michael J Gruber
Message 2 of 5 in “how to create a diff in old file new file format (for code reviews)”
  1. aerosmithDec 14, 2010
  2. Michael J GruberDec 14, 2010
  3. 1/2 git-difftool.txt: correct the description of $BASE and describe $MERGEDMichael J Gruber, Dec 14, 2010
  4. 2/2 difftool: provide basename to external toolsMichael J Gruber, Dec 14, 2010
  5. Seshu ParvataneniDec 16, 2010

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.