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

5 messages from 2010-12-14 to 2010-12-16. Participants: aerosmith, Michael J Gruber, Seshu Parvataneni.
Thread: https://gitlist.dev/t/26043

## aerosmith, 2010-12-14 00:07

Subject: how to create a diff in old file new file format (for code reviews)
Message-ID: <1292285257962-5832810.post@n2.nabble.com>
URL: https://gitlist.dev/e/1292285257962-5832810.post%40n2.nabble.com

```

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.
-- 
View this message in context: http://git.661346.n2.nabble.com/how-to-create-a-diff-in-old-file-new-file-format-for-code-reviews-tp5832810p5832810.html
Sent from the git mailing list archive at Nabble.com.

```

## Michael J Gruber, 2010-12-14 09:17

Subject: Re: how to create a diff in old file new file format (for code reviews)
Message-ID: <4D073619.2010103@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4D073619.2010103%40drmicha.warpmail.net
In-Reply-To: <1292285257962-5832810.post@n2.nabble.com>

```
aerosmith venit, vidit, dixit 14.12.2010 01:07:
> 
> 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

```

## Michael J Gruber, 2010-12-14 09:18

Subject: [PATCH 1/2] git-difftool.txt: correct the description of $BASE and describe $MERGED
Message-ID: <0833a4451b70db4c4e0be5753be53e262a9c5628.1292317348.git.git@drmicha.warpmail.net>
URL: https://gitlist.dev/e/0833a4451b70db4c4e0be5753be53e262a9c5628.1292317348.git.git%40drmicha.warpmail.net
In-Reply-To: <4D073619.2010103@drmicha.warpmail.net>

```
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 Documentation/git-difftool.txt |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt
index 6fffbc7..756d95d 100644
--- a/Documentation/git-difftool.txt
+++ b/Documentation/git-difftool.txt
@@ -56,8 +56,9 @@ the configured command line will be invoked with the following
 variables available: `$LOCAL` is set to the name of the temporary
 file containing the contents of the diff pre-image and `$REMOTE`
 is set to the name of the temporary file containing the contents
-of the diff post-image.  `$BASE` is provided for compatibility
-with custom merge tool commands and has the same value as `$LOCAL`.
+of the diff post-image.  `$MERGED` is the name of the file which is
+being compared. `$BASE` is provided for compatibility
+with custom merge tool commands and has the same value as `$MERGED`.
 
 -x <command>::
 --extcmd=<command>::
-- 
1.7.3.3.739.g52f77.dirty

```

## Michael J Gruber, 2010-12-14 09:18

Subject: [PATCH 2/2] difftool: provide basename to external tools
Message-ID: <3a5944cb9af7b6b69dc0bdefdfd052b33fcd9a59.1292317348.git.git@drmicha.warpmail.net>
URL: https://gitlist.dev/e/3a5944cb9af7b6b69dc0bdefdfd052b33fcd9a59.1292317348.git.git%40drmicha.warpmail.net
In-Reply-To: <4D073619.2010103@drmicha.warpmail.net>

```
Currently, only configured diff helpers get the basename of the file
being compared. Tools specified with "git difftool -x" only get the
names of temporary files for the different versions.

Export BASE so that an external tool can read the name from the
environment. Rather than using a third argument, this avoids breaking
existing scripts which may somewhat carelessly be using "$@" rather than
"$1" "$2".

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 Documentation/git-difftool.txt |    1 +
 git-difftool--helper.sh        |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt
index 756d95d..db87f1d 100644
--- a/Documentation/git-difftool.txt
+++ b/Documentation/git-difftool.txt
@@ -65,6 +65,7 @@ with custom merge tool commands and has the same value as `$MERGED`.
 	Specify a custom command for viewing diffs.
 	'git-difftool' ignores the configured defaults and runs
 	`$command $LOCAL $REMOTE` when this option is specified.
+	Additionally, `$BASE` is set in the environment.
 
 -g::
 --gui::
diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh
index 524f5ea..0594bf7 100755
--- a/git-difftool--helper.sh
+++ b/git-difftool--helper.sh
@@ -49,6 +49,7 @@ launch_merge_tool () {
 	fi
 
 	if use_ext_cmd; then
+		export BASE
 		eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
 	else
 		run_merge_tool "$merge_tool"
-- 
1.7.3.3.739.g52f77.dirty

```

## Seshu Parvataneni, 2010-12-16 03:33

Subject: Re: [solved] how to create a diff in old file new file format (for code reviews)
Message-ID: <415120.5940.qm@web34306.mail.mud.yahoo.com>
URL: https://gitlist.dev/e/415120.5940.qm%40web34306.mail.mud.yahoo.com
In-Reply-To: <4D073619.2010103@drmicha.warpmail.net>

```
Hi Michael,

Thanks very much for the reply. Your example with the difftool worked. This was what I was looking for.



--- On Tue, 12/14/10, Michael J Gruber <git@drmicha.warpmail.net> wrote:

> From: Michael J Gruber <git@drmicha.warpmail.net>
> Subject: Re: how to create a diff in old file new file format (for code reviews)
> To: "aerosmith" <parvata@rocketmail.com>
> Cc: git@vger.kernel.org
> Date: Tuesday, December 14, 2010, 1:17 AM
> aerosmith venit, vidit, dixit
> 14.12.2010 01:07:
> > 
> > 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
> --
> To unsubscribe from this list: send the line "unsubscribe
> git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


      

```
