how to create a diff in old file new file format (for code reviews)
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.
Signature · 2 lines
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.
aerosmith venit, vidit, dixit 14.12.2010 01:07:
Quoted 10 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
PATCH 1/2 git-difftool.txt: correct the description of $BASE and describe $MERGED
--- Documentation/git-difftool.txt | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
Documentation/git-difftool.txt +3 -2
@@ -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>::
Signature · 1 line
1.7.3.3.739.g52f77.dirty
PATCH 2/2 difftool: provide basename to external tools
In reply to Michael J GruberCurrently, 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".
--- Documentation/git-difftool.txt | 1 + git-difftool--helper.sh | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
Documentation/git-difftool.txt +1 -0
@@ -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::
git-difftool--helper.sh +1 -0
@@ -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"
Signature · 1 line
1.7.3.3.739.g52f77.dirty
Hi Michael,
Thanks very much for the reply. Your example with the difftool worked. This was what I was looking for.
Quoted 64 lines · Michael J Gruber
From: Michael J Gruber <[email protected]>
Subject: Re: how to create a diff in old file new file format (for code reviews)
To: "aerosmith" <[email protected]>
Cc: [email protected]
Date: Tuesday, December 14, 2010, 1:17 AM
aerosmith venit, vidit, dixit
14.12.2010 01:07:Quoted 4 lines
Hi,
I am trying to create a diff such that the original
file (entire file) is
Quoted 1 line
saved something like file1.h.old and the new modified
file as file1.h.new. I
Quoted 1 line
have read the various options for git-diff* tools but
could not find one
Quoted 1 line
such utility. All I get is the removals and additions
as a diff. Does anyone
Quoted 1 line
know how to create one with the help the available git
utils? The only
Quoted 1 line
method that I can think of is to do everything
manually. Any help w.r.t.
Quoted 1 line
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".newEven 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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html