git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: how to diff versions of a file

From
Jeff King <peff@peff.net>
Date
Feb 3, 2009, 07:34 UTC
Message-ID
<20090203073450.GE21367@sigill.intra.peff.net>
In-Reply-To
<1c5969370902022100h7c03bbb6h2d9f443f877d89ec@mail.gmail.com>
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
Previous: Matt Graham
Message 5 of 5 in “how to diff versions of a file”
  1. Matt GrahamFeb 3, 2009
  2. david@lang.hmFeb 3, 2009
  3. Junio C HamanoFeb 3, 2009
  4. Matt GrahamFeb 3, 2009
  5. Jeff KingFeb 3, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.