* how to diff versions of a file
@ 2009-02-03 5:00 Matt Graham
2009-02-03 6:08 ` david
2009-02-03 7:34 ` Jeff King
0 siblings, 2 replies; 5+ messages in thread
From: Matt Graham @ 2009-02-03 5:00 UTC (permalink / raw)
To: git
Hi,
I'm curious if there's a way to diff between 2 arbitrary versions of a file.
For example, how can I see the diff between tree.c on HEAD and from 3
edits (of tree.c) ago?
I can do git log and then manually use commit names to do the diff,
but I'm hoping there's a single command that will let me do that.
Thanks,
Matt
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: how to diff versions of a file
2009-02-03 5:00 how to diff versions of a file Matt Graham
@ 2009-02-03 6:08 ` david
2009-02-03 6:34 ` Junio C Hamano
2009-02-03 7:34 ` Jeff King
1 sibling, 1 reply; 5+ messages in thread
From: david @ 2009-02-03 6:08 UTC (permalink / raw)
To: Matt Graham; +Cc: git
On Tue, 3 Feb 2009, Matt Graham wrote:
> Hi,
> I'm curious if there's a way to diff between 2 arbitrary versions of a file.
>
> For example, how can I see the diff between tree.c on HEAD and from 3
> edits (of tree.c) ago?
>
> I can do git log and then manually use commit names to do the diff,
> but I'm hoping there's a single command that will let me do that.
I don't think it's trivial
If you just wanted three commits ago you could do
git diff HEAD..HEAD^^^ tree.c
but three changes to tree.c ago I think you need to do multiple iterations
of git blame to find out what commit was three edits ago.
after you have the commit for three edits ago you do
git diff HEAD..COMMITID tree.c
David Lang
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: how to diff versions of a file
2009-02-03 6:08 ` david
@ 2009-02-03 6:34 ` Junio C Hamano
2009-02-03 13:48 ` Matt Graham
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2009-02-03 6:34 UTC (permalink / raw)
To: david; +Cc: Matt Graham, git
david@lang.hm writes:
> I don't think it's trivial
I think you meant to say it _is_ trivial.
> If you just wanted three commits ago you could do
>
> git diff HEAD..HEAD^^^ tree.c
That would give you a reverse diff; I think you probably meant the other
way around, "git diff HEAD~3 HEAD tree.c".
> but three changes to tree.c ago I think you need to do multiple
> iterations of git blame to find out what commit was three edits ago.
git diff $(git rev-list -3 HEAD -- tree.c | sed -n -e '$p') HEAD -- tree.c
This assumes that the history is linear but your statement "three edits
ago" already assumes that, so...
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: how to diff versions of a file
2009-02-03 5:00 how to diff versions of a file Matt Graham
2009-02-03 6:08 ` david
@ 2009-02-03 7:34 ` Jeff King
1 sibling, 0 replies; 5+ messages in thread
From: Jeff King @ 2009-02-03 7:34 UTC (permalink / raw)
To: Matt Graham; +Cc: git
On Tue, Feb 03, 2009 at 12:00:51AM -0500, Matt Graham wrote:
> I'm curious if there's a way to diff between 2 arbitrary versions of a file.
>
> For example, how can I see the diff between tree.c on HEAD and from 3
> edits (of tree.c) ago?
Others have suggested diffing between two arbitrary revisions, and
limiting the diff by path. E.g.:
git diff HEAD~3 HEAD -- tree.c
which works just fine. But I find it more intuitive to simply specify
the diff between two blobs (or trees, if you want), like:
git diff HEAD~3:tree.c HEAD:tree.c
The added bonus is that you can also use this syntax to diff two files
with different names.
-Peff
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: how to diff versions of a file
2009-02-03 6:34 ` Junio C Hamano
@ 2009-02-03 13:48 ` Matt Graham
0 siblings, 0 replies; 5+ messages in thread
From: Matt Graham @ 2009-02-03 13:48 UTC (permalink / raw)
To: Junio C Hamano; +Cc: david, git
On Tue, Feb 3, 2009 at 01:34, Junio C Hamano <gitster@pobox.com> wrote:
> david@lang.hm writes:
>
>> I don't think it's trivial
>
> I think you meant to say it _is_ trivial.
>
>> If you just wanted three commits ago you could do
>>
>> git diff HEAD..HEAD^^^ tree.c
>
> That would give you a reverse diff; I think you probably meant the other
> way around, "git diff HEAD~3 HEAD tree.c".
>
>> but three changes to tree.c ago I think you need to do multiple
>> iterations of git blame to find out what commit was three edits ago.
>
> git diff $(git rev-list -3 HEAD -- tree.c | sed -n -e '$p') HEAD -- tree.c
>
> This assumes that the history is linear but your statement "three edits
> ago" already assumes that, so...
Thanks Junio, this is exactly what I was asking for.
And thanks for the tip about it depending on the history being linear.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-02-03 13:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-03 5:00 how to diff versions of a file Matt Graham
2009-02-03 6:08 ` david
2009-02-03 6:34 ` Junio C Hamano
2009-02-03 13:48 ` Matt Graham
2009-02-03 7:34 ` Jeff King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).