{"thread":{"id":"17520","subject":"how to diff versions of a file","startedAt":"2009-02-03T05:00:51Z","lastAt":"2009-02-03T13:48:46Z","messageCount":5,"participants":["Matt Graham","david@lang.hm","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"102919","messageId":"1c5969370902022100h7c03bbb6h2d9f443f877d89ec@mail.gmail.com","threadId":"17520","inReplyTo":null,"subject":"how to diff versions of a file","fromName":"Matt Graham","fromEmail":"mdg149@gmail.com","sentAt":"2009-02-03T05:00:51Z","receivedAt":"2009-02-03T05:00:51Z","isPatch":false,"sender":{"key":"mdg149@gmail.com","avatar":"https://gravatar.com/avatar/a1f130a60a6550f75e8d7d3849e58e46494f36bfaf764a38cfd695ac85de8576?d=mp&s=160"},"body":"Hi,\nI'm curious if there's a way to diff between 2 arbitrary versions of a file.\n\nFor example, how can I see the diff between tree.c on HEAD and from 3\nedits (of tree.c) ago?\n\nI can do git log and then manually use commit names to do the diff,\nbut I'm hoping there's a single command that will let me do that.\n\nThanks,\nMatt\n"},{"id":"102920","messageId":"alpine.DEB.1.10.0902022206060.28633@asgard.lang.hm","threadId":"17520","inReplyTo":"1c5969370902022100h7c03bbb6h2d9f443f877d89ec@mail.gmail.com","subject":"Re: how to diff versions of a file","fromName":"","fromEmail":"david@lang.hm","sentAt":"2009-02-03T06:08:44Z","receivedAt":"2009-02-03T06:08:44Z","isPatch":false,"sender":{"key":"david@lang.hm","avatar":null},"body":"On Tue, 3 Feb 2009, Matt Graham wrote:\n\n> Hi,\n> I'm curious if there's a way to diff between 2 arbitrary versions of a file.\n>\n> For example, how can I see the diff between tree.c on HEAD and from 3\n> edits (of tree.c) ago?\n>\n> I can do git log and then manually use commit names to do the diff,\n> but I'm hoping there's a single command that will let me do that.\n\nI don't think it's trivial\n\nIf you just wanted three commits ago you could do\n\ngit diff HEAD..HEAD^^^ tree.c\n\nbut three changes to tree.c ago I think you need to do multiple iterations \nof git blame to find out what commit was three edits ago.\n\nafter you have the commit for three edits ago you do\ngit diff HEAD..COMMITID tree.c\n\nDavid Lang\n"},{"id":"102927","messageId":"7vk588do5q.fsf@gitster.siamese.dyndns.org","threadId":"17520","inReplyTo":"alpine.DEB.1.10.0902022206060.28633@asgard.lang.hm","subject":"Re: how to diff versions of a file","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-02-03T06:34:25Z","receivedAt":"2009-02-03T06:34:25Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"david@lang.hm writes:\n\n> I don't think it's trivial\n\nI think you meant to say it _is_ trivial.\n\n> If you just wanted three commits ago you could do\n>\n> git diff HEAD..HEAD^^^ tree.c\n\nThat would give you a reverse diff; I think you probably meant the other\nway around, \"git diff HEAD~3 HEAD tree.c\".\n\n> but three changes to tree.c ago I think you need to do multiple\n> iterations of git blame to find out what commit was three edits ago.\n\ngit diff $(git rev-list -3 HEAD -- tree.c | sed -n -e '$p') HEAD -- tree.c\n\nThis assumes that the history is linear but your statement \"three edits\nago\" already assumes that, so...\n"},{"id":"102934","messageId":"20090203073450.GE21367@sigill.intra.peff.net","threadId":"17520","inReplyTo":"1c5969370902022100h7c03bbb6h2d9f443f877d89ec@mail.gmail.com","subject":"Re: how to diff versions of a file","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-02-03T07:34:50Z","receivedAt":"2009-02-03T07:34:50Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Feb 03, 2009 at 12:00:51AM -0500, Matt Graham wrote:\n\n> I'm curious if there's a way to diff between 2 arbitrary versions of a file.\n> \n> For example, how can I see the diff between tree.c on HEAD and from 3\n> edits (of tree.c) ago?\n\nOthers have suggested diffing between two arbitrary revisions, and\nlimiting the diff by path. E.g.:\n\n  git diff HEAD~3 HEAD -- tree.c\n\nwhich works just fine.  But I find it more intuitive to simply specify\nthe diff between two blobs (or trees, if you want), like:\n\n  git diff HEAD~3:tree.c HEAD:tree.c\n\nThe added bonus is that you can also use this syntax to diff two files\nwith different names.\n\n-Peff\n"},{"id":"102963","messageId":"1c5969370902030548g284e8ae2i7dc3a866c4337a5f@mail.gmail.com","threadId":"17520","inReplyTo":"7vk588do5q.fsf@gitster.siamese.dyndns.org","subject":"Re: how to diff versions of a file","fromName":"Matt Graham","fromEmail":"mdg149@gmail.com","sentAt":"2009-02-03T13:48:46Z","receivedAt":"2009-02-03T13:48:46Z","isPatch":false,"sender":{"key":"mdg149@gmail.com","avatar":"https://gravatar.com/avatar/a1f130a60a6550f75e8d7d3849e58e46494f36bfaf764a38cfd695ac85de8576?d=mp&s=160"},"body":"On Tue, Feb 3, 2009 at 01:34, Junio C Hamano <gitster@pobox.com> wrote:\n> david@lang.hm writes:\n>\n>> I don't think it's trivial\n>\n> I think you meant to say it _is_ trivial.\n>\n>> If you just wanted three commits ago you could do\n>>\n>> git diff HEAD..HEAD^^^ tree.c\n>\n> That would give you a reverse diff; I think you probably meant the other\n> way around, \"git diff HEAD~3 HEAD tree.c\".\n>\n>> but three changes to tree.c ago I think you need to do multiple\n>> iterations of git blame to find out what commit was three edits ago.\n>\n> git diff $(git rev-list -3 HEAD -- tree.c | sed -n -e '$p') HEAD -- tree.c\n>\n> This assumes that the history is linear but your statement \"three edits\n> ago\" already assumes that, so...\n\nThanks Junio, this is exactly what I was asking for.\n\nAnd thanks for the tip about it depending on the history being linear.\n"}]}