threads / discuss / 27085

Interdiff between amended commits

Subject: Interdiff between amended commits

## tl;dr

4 messages between Apr 13, 2011 and Apr 14, 2011.

replies: 3people: 2as markdown or json

Stefan Haller· Apr 13, 2011, 11:54 UTC · lore

I'd like to show an interdiff between two commits, e.g. when a commit was amended.

I'm aware of the "intercommit" alias in the git wiki:
  $ git show commit1 > .git/commit1 && git show commit2 > .git/commit2 && interdiff .git/commit[12]

It only works for simple cases though, and I'd also like to avoid the dependency to an external tool if possible.

So one thing I came up with is this:
  git checkout commit1^
  git cherry-pick --no-commit commit2
  git diff --cached
Two problems:
1) It requires a non-bare clone. At the place where I need it (on a
   server that sends commit emails) I only have a bare clone, so ideally
   I'd like something that doesn't need a working directory at all.
2) I'm not sure what to do if the cherry-pick doesn't apply cleanly.
   (The interdiff command has the same problem, of course).
   I don't even know what information I want to see in that case;
   anybody have an idea?
Any other thoughts about this are appreciated.
-- 
Stefan Haller
Berlin, Germany
http://www.haller-berlin.de/
Michael J Gruber· Apr 14, 2011, 07:08 UTC · re: Stefan Haller · lore

Re: Interdiff between amended commits

Stefan Haller venit, vidit, dixit 13.04.2011 13:54:
Show 7 quoted lines
> I'd like to show an interdiff between two commits, e.g. when a commit
> was amended.
> 
> I'm aware of the "intercommit" alias in the git wiki:
> 
>   $ git show commit1 > .git/commit1 && git show commit2 > .git/commit2 && interdiff .git/commit[12]
> 

This basically computes the diff between two patches, using a tool which groks the patch format.

> It only works for simple cases though, and I'd also like to avoid the
> dependency to an external tool if possible.

You could use git diff --no-index instead, so that would work in really simple cases only, probably.

Show 6 quoted lines
> 
> So one thing I came up with is this:
> 
>   git checkout commit1^
>   git cherry-pick --no-commit commit2
>   git diff --cached

That does something completely different. It compares the tree of commit1^ with the tree of (commit1^ with commit2's patch applied). I don't see how commit1's patch plays any role here.

Depending on what your actual use case, you may be happier with "git diff commit1 commit2". Alternatively, you may produce a fake merge with parents commit1 and commit2 and tree commit1^ and look at "show -R -c" for that. Sounds weird, I know ;)

Michael
Stefan Haller· Apr 14, 2011, 08:09 UTC · re: Michael J Gruber · lore

Re: Interdiff between amended commits

Michael J Gruber <git@drmicha.warpmail.net> wrote:
Show 9 quoted lines
> > So one thing I came up with is this:
> > 
> >   git checkout commit1^
> >   git cherry-pick --no-commit commit2
> >   git diff --cached
> 
> That does something completely different. It compares the tree of
> commit1^ with the tree of (commit1^ with commit2's patch applied). I
> don't see how commit1's patch plays any role here.
Sorry, that was just a typo.  I meant
  git diff --cached commit1
as the last line, of course.
Alternatively, I could do it the other way round, by saying
  git checkout commit2^
  git cherry-pick --no-commit commit1
  git diff --cached -R commit2

That should produce the same result (except maybe for the line numbers in the hunk headers), as long as the cherry-pick didn't have conflicts.

> Depending on what your actual use case, you may be happier with "git
> diff commit1 commit2"

No, that's not what I want (except when commit1 and commit2 have the same parent). This would also show the differences between the parents of commit1 and commit2; I don't want to include those.

My actual use case is that I have a central repository that sends out commit emails; when someone does an interactive rebase and amends a commit in the middle of a branch, I want to match up corresponding commits based on their subject line, and then send an email showing how the diff for that commit changed.

-- 
Stefan Haller
Berlin, Germany
http://www.haller-berlin.de/
Michael J Gruber· Apr 14, 2011, 08:47 UTC · re: Stefan Haller · lore

Re: Interdiff between amended commits

Stefan Haller venit, vidit, dixit 14.04.2011 10:09:
Show 39 quoted lines
> Michael J Gruber <git@drmicha.warpmail.net> wrote:
> 
>>> So one thing I came up with is this:
>>>
>>>   git checkout commit1^
>>>   git cherry-pick --no-commit commit2
>>>   git diff --cached
>>
>> That does something completely different. It compares the tree of
>> commit1^ with the tree of (commit1^ with commit2's patch applied). I
>> don't see how commit1's patch plays any role here.
> 
> Sorry, that was just a typo.  I meant
> 
>   git diff --cached commit1
> 
> as the last line, of course.
> 
> Alternatively, I could do it the other way round, by saying
> 
>   git checkout commit2^
>   git cherry-pick --no-commit commit1
>   git diff --cached -R commit2
> 
> That should produce the same result (except maybe for the line numbers
> in the hunk headers), as long as the cherry-pick didn't have conflicts.
> 
>> Depending on what your actual use case, you may be happier with "git
>> diff commit1 commit2"
> 
> No, that's not what I want (except when commit1 and commit2 have the
> same parent).  This would also show the differences between the parents
> of commit1 and commit2; I don't want to include those.
> 
> My actual use case is that I have a central repository that sends out
> commit emails; when someone does an interactive rebase and amends a
> commit in the middle of a branch, I want to match up corresponding
> commits based on their subject line, and then send an email showing how
> the diff for that commit changed.

In that case, "git diff --no-index" on the two patches (i.e. the alias you found with "interdiff" replaced) may be worth a try. We should be able to teach our diff machinery about our diffs :) I mean, see userdiff and funcname.

Michael

← back to recent threads